Macro Code to Attach a PDF file created by any user

neiloboy1986

New Member
Joined
May 2, 2022
Messages
1
Office Version
  1. 2019
Platform
  1. 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
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,214,788
Messages
6,121,575
Members
449,039
Latest member
Arbind kumar

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