neiloboy1986
New Member
- Joined
- May 2, 2022
- Messages
- 1
- Office Version
- 2019
- Platform
- Windows
Hi, what's the macro code to attach a pdf file created by any user?
Here is what i have so far. I just can't find a working code after .attachment add to collate the two actions (export pdf by any user + attach the created pdf).
With Worksheets("PDF")
iVis = .Visible
.Visible = xlSheetVisible
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\FILENAME.pdf", _
OpenAfterPublish:=True
.Visible = iVis
End With
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
Set Mail_Object = CreateObject("Outlook.application")
With Mail_Object.CreateItem(0)
.To = "email@address.com"
.Subject = "SUBJECT NAME " & Format(Date, "ddmmyyy")
.Body = "BODY CONTENT"
.Attachments.Add
.Display
.Send
End With
Set OutlookMailItem = Nothing
Set OutLookApp = Nothing
End Sub
Here is what i have so far. I just can't find a working code after .attachment add to collate the two actions (export pdf by any user + attach the created pdf).
With Worksheets("PDF")
iVis = .Visible
.Visible = xlSheetVisible
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\FILENAME.pdf", _
OpenAfterPublish:=True
.Visible = iVis
End With
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
Set Mail_Object = CreateObject("Outlook.application")
With Mail_Object.CreateItem(0)
.To = "email@address.com"
.Subject = "SUBJECT NAME " & Format(Date, "ddmmyyy")
.Body = "BODY CONTENT"
.Attachments.Add
.Display
.Send
End With
Set OutlookMailItem = Nothing
Set OutLookApp = Nothing
End Sub