Hello all,

I am trying to get a Word document to create a PDF of certain specified pages of the current document and then attach it to an email generated in Outlook.

Weirdly, the code below works fine if the path listed in filename already exists. It adds it as an attachment in Outlook without a problem. But if the application.printout code below creates a completely new PDF, Word shows the error message:

Run-time error '-2147024894 (80070002)'; Cannot find this file. Verify the path and file name are correct.

When I run the fileexist function below immediately after running Application.printout, it confirms that the application.printout code does not print the PDF until after the entire code has completed. That explains why Outlook has trouble finding the file.

Does anybody know how to get around this problem/get Word to print the PDF page immediately so that the attachment can be added to Outlook without errors?

N.B. ActiveDocument.ExportAsFixedFormat for creating the PDF is not an option as far as I can tell, since the PDF I am creating will have scattered pages, not a range of pages from X to Y.

Many thanks in advance for your contributions!


Dim OlApp As Outlook.Application
Dim ObjMail As Outlook.MailItem
Dim filename As String
filename = "C:\Users\Davec\Downloads\Trial\Bop.pdf"

ActivePrinter = "Microsoft Print to PDF"
Application.PrintOut range:=wdPrintAllDocument, Append:=False, Item:= _
wdPrintDocumentWithMarkup, Copies:=1, pages:="", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=True, _
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0, OutputFileName:=filename


'MsgBox FileExist(filename)


Set OlApp = Outlook.Application
Set ObjMail = OlApp.CreateItem(olMailItem)
ObjMail.Attachments.Add Source:=filename
Set ObjMail = Outlook.ActiveInspector.CurrentItem
ObjMail.Recipients.ResolveAll