Issue opening Outlook with VBA

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
625
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
So I now have two versions of Outlook, the new version as well as the old version. So my code below does not work. I am thinking that is the problem. I am getting a message stating "We detected a problem launching the new Outlook. Please try again later." I am still trying to decide which Outlook to keep. Is there a way to only reference the Outlook version I want to open? Here's the code I used. Thank you.

VBA Code:
Sub Email()

    Dim olApp As Object
    Dim MI As Object
    Dim sPath As String, sFileName As String, CurrentTime As String, sFileLocation As String
    Dim wbAnswer As Integer, EmilAnswer As Integer
    
    sPath = "C:\Users\" & Environ("username") & "\OneDrive\Desktop\"
    
    sFileName = Range("B8").Text & "_" & Format(Now(), "mm.dd.yyyy_hhmm") & ".pdf"
    sFileLocation = sPath & sFileName
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFileLocation
    ActiveWorkbook.Save
    
    EmailAnswer = MsgBox("Do you want to email this pdf?", vbYesNo + vbDefaultButton1 + vbQuestion, "Email: " & sFileName)
    If EmailAnswer = vbYes Then
        Set olApp = CreateObject("Outlook.Application")
        Set MI = olApp.CreateItem(OlMailItem)
        
        With MI
            .To = ""
            .CC = ""
            .Subject = "Purchase Order Number: " & PONumber
            .Attachments.Add sPath & sFileName
            .Body = Salutation & FirstName1 & "," & vbNewLine & vbNewLine & "Please allow me to purchase this." & vbNewLine & vbNewLine
            .Display
        End With
        Set MI = Nothing
        Set olApp = Nothing
    Else
        Exit Sub
    End If
    wbAnswer = MsgBox("Are you sure you want to close this workbook and Excel?", vbYesNo + vbDefaultButton1 + vbQuestion, "WORKBOOK: " & ActiveWorkbook.Name)
    If wbAnswer = vbYes Then
        ActiveWorkbook.Save
        Application.Quit
    Else
        Exit Sub
    End If

End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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