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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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