Opening Outlook to send and email

cpapplefamily

New Member
Joined
Jul 8, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I have been using this code for some time and since Outlook added the "New Outlook" this seems to be opening up an old version of outlook resulting in my emails not appearing in the sent folder. This could be a windows thing but it may be possible the code needs to point to a different application. When I toogle back to the "Old Outlook" using the toggle switch in the Outlook application the created and sent email does show.

Here is the code
VBA Code:
'Open Outlook Email

    Dim a As Integer
    Dim objOutlook As Object
    Dim objMail As Object
    Dim rngTo As String
    Dim rngCc1 As Object
    Dim rngSubject As String
    Dim rngAttach As Range
    Dim rngBody As String
    Dim sCC As String
    Dim emailRng As Range, cl As Range
    Dim Signature As String
    
    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)

    Signature = objMail.HTMLBody

    rngSubject = ActiveWorkbook.Sheets("PO Request").Range("C12") & " - Purchase Request - " & ActiveWorkbook.Sheets("PO Request").Range("C3")
    rngTo = ActiveWorkbook.Sheets("Email").Range("A1")
    rngBody = ActiveWorkbook.Sheets("Email").Range("A2")

    Set emailRng = Worksheets("PO Request").Range("C17:C19")
    For Each cl In emailRng
        sCC = sCC & ";" & cl.Value
    Next

    With objMail
        .Display
        .To = rngTo
        .CC = sCC
        .Subject = rngSubject
        .Attachments.Add sFileSaveName1
        '.Attachments.Add sFileSaveName2
        .HTMLBody = rngBody & .HTMLBody
    End With


    ' copy Name to Clip Board
    Dim savedAsNameWithExt
    Dim savedAsNameWithOutExt As String
    savedAsNameWithExt = Split(sFileSaveName1, "\")
    
    savedAsNameWithOutExt = Left(savedAsNameWithExt(UBound(savedAsNameWithExt)), InStr(savedAsNameWithExt(UBound(savedAsNameWithExt)), ".") - 1)
    'MsgBox savedAsNameWithOutExt
    Clipboard savedAsNameWithOutExt
    

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top