jcbaggett16
New Member
- Joined
- Feb 14, 2024
- Messages
- 9
- Office Version
- 365
- Platform
- Windows
Alright, I have my code saving my file and attaching it to outlook. My issue is it only works if outlook is open. How can I get it to open outlook if not already open?
Sub PDF()
ChDir "C:\Users\...\Desktop\New folder"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\...\Desktop\New folder\Transition " & Range("H2").Text
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim myAttachments As Object
Set OutLookApp = CreateObject("Outlook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments
With OutLookMailItem
.To = ""
.Subject = ""
.Body = ""
myAttachments.Add "C:\Users\...\Desktop\New folder\Transition " & Range("H2").Text & ".pdf"
'.send
.Display
End With
Set OutLookMailItem = Nothing
Set OutLookApp = Nothing
End Sub
Sub PDF()
ChDir "C:\Users\...\Desktop\New folder"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\...\Desktop\New folder\Transition " & Range("H2").Text
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim myAttachments As Object
Set OutLookApp = CreateObject("Outlook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments
With OutLookMailItem
.To = ""
.Subject = ""
.Body = ""
myAttachments.Add "C:\Users\...\Desktop\New folder\Transition " & Range("H2").Text & ".pdf"
'.send
.Display
End With
Set OutLookMailItem = Nothing
Set OutLookApp = Nothing
End Sub