jcbaggett16
New Member
- Joined
- Feb 14, 2024
- Messages
- 9
- Office Version
- 365
- Platform
- Windows
Please help, I have it attaching to email if outlook is open. If its not open it locks up excel and will not allow outlook to open automatically or manually.
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
On Error Resume Next
Set OutLookApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If OutLookApp Is Nothing Then
Set OutLookApp = CreateObject("Outlook.Application")
Dim OutLookMailItem As Object
Dim myAttachments As Object
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
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
On Error Resume Next
Set OutLookApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If OutLookApp Is Nothing Then
Set OutLookApp = CreateObject("Outlook.Application")
Dim OutLookMailItem As Object
Dim myAttachments As Object
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