Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- 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