Copy link to clipboard
Copied
Hi,
I have a mixture of Word/PDF documents which I would like to print in the right sequence using MS Word VBA. Everything works fine. My code for printing PDF documents using DDE is as follows:
Dim RetVal
Dim chanNo
'Open Adobe Acrobat
RetVal = Shell("C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe", vbHide)
chanNo = DDEInitiate("AcroViewA21", "Control")
'File is opened and displayed with DocOpen
DDEExecute chanNo, "[DocOpen(""" & myDoc & """)]"
'Print the file
DDEExecute chanNo, "[FilePrintTo(""" & myDoc & """,""" & myPrinter & ""","""")]"
'Close PDF file
DDEExecute chanNo, "[DocClose(""" & myDoc & """)]"
'Close Acrobat
DDEExecute chanNo, "[AppExit( )]"
Where myDoc and myPrinter need to be defined.
I have read that DDE is now old technology and is only available for backwards compatibility and that OLE should be used instead. I am not a programmer, so I'm not sure how important this is.
Can someone please provide an OLE solution to do the same task, just to ensure this is futureproof. In particular, it is important to be able set the printer.
Any help would be greatly appreciated. Thanks!
1 Correct answer
I've managed to answer my own problem. Here's the code I've cobbled together by referring to various sources:
Dim AcroApp As AcroApp
Dim AcroAVDoc As AcroAVDoc
Dim AcroPDDoc As AcroPDDoc
Dim myDoc As String
Dim myPrinter As String
Dim RetVal
CreateObject("WScript.Network").SetDefaultPrinter myPrinter
Set AcroApp = CreateObject("AcroExch.App")
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
If AcroAVDoc.Open(myDoc, "") Then
Set AcroPDDoc = AcroAVDoc.GetPDDoc
NumOfPages = AcroPDDoc.GetNumPages - 1
Set AcroPDDo
Copy link to clipboard
Copied
Try the forum for Acrobat SDK.
Copy link to clipboard
Copied
Thank you. Is there an easy way to do that - to change my post to another forum?
Copy link to clipboard
Copied
Hi,
Moved for you.
Copy link to clipboard
Copied
Thank you. I hope someone can help!
Copy link to clipboard
Copied
I've managed to answer my own problem. Here's the code I've cobbled together by referring to various sources:
Dim AcroApp As AcroApp
Dim AcroAVDoc As AcroAVDoc
Dim AcroPDDoc As AcroPDDoc
Dim myDoc As String
Dim myPrinter As String
Dim RetVal
CreateObject("WScript.Network").SetDefaultPrinter myPrinter
Set AcroApp = CreateObject("AcroExch.App")
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
If AcroAVDoc.Open(myDoc, "") Then
Set AcroPDDoc = AcroAVDoc.GetPDDoc
NumOfPages = AcroPDDoc.GetNumPages - 1
Set AcroPDDoc = CreateObject("AcroExch.PDDoc")
RetVal = AcroAVDoc.PrintPagesSilent(0, NumOfPages, 2, False, False)
AcroApp.CloseAllDocs
End If
AcroApp.Exit
Set AcroPDDoc = Nothing
Set AcroAVDoc = Nothing
Set AcroApp = Nothing
Where myDoc and myPrinter need to be defined.
This is all done in the background. If you need to see things happening, you can also add in:
AcroApp.Show
AcroAVDoc.BringToFront
The above is for a Windows 10 system and sets the main default printer of the Windows system. Can anyone please tell me how to set the printer within Acrobat. What would the VBA code be for that? Thanks!
Copy link to clipboard
Copied
Hi, were you able to indicate the number of copies to print?

