Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a PDF document from VBA

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I've added a reference to Acrobat in the project and written the following code...
Code:
Sub PrintPDF(ByVal sFile As String)

  Dim PDFApp As Object
  
On Error GoTo EH_PrintPDF

    'create instance of PDF
    Set PDFApp = CreateObject("Acrobat.Application")
    'Open document
    PDFApp.Documents.Open sFile
    'print
    PDFApp.ActiveDocument.PrintOut False, , wdPrintAllDocument
    'close Word without saving
    PDFApp.Quit False
    'free reference
    Set PDFApp = Nothing
    sDoUpd = "Yes"

Exit_PrintPDF:
    Exit Sub
    
EH_PrintPDF:
    MsgBox "Error in PrintPDF " & Error(Err) & ", " & CStr(Err)
    sDoUpd = "No"
    Resume Exit_PrintPDF
    
End Sub

But I get an error "activex component can't create object".

I've done G! and have found lots about creating a PDF, which I can do with the PDFCreator plugin no problem.

I have also found some stuff for doing it with VB6, but I can't seem to find anything specifically for VBA.

Can someone please help me print a PDF from VBA.

thanks,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
I have also found some stuff for doing it with VB6
So, It should work with VBA too, doesn'it ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
well the one I found was a zip file which contained some source files and I didn't know what to do with them to open them.

I assumed you need visual studio, but if you can advise if they are compatible with MS Access and what I do with a .frm file, I'll give it a whirl.

I tried openining one of them witn notepad but it didn't seem to have any VB code in it.

So sort of fumbling in the dark at the moment.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
I fianlly found the answer here :
I'm not suprised no-one here could answer my thread , it's rediculously complicated just to print a PDF file.

I wish to thank JoeBB3 for his solution and effort in answering this complicated problem with VBA and PDF's

I would point out that although the document is printed and closed it still leaves acrobat open?

So if anyone has any ideas on how to ensure acrobat fully closes afterwards I would appreciate it.

Again nice one JoeBB3, for your very helpfull post to this very annoying problem! [2thumbsup]



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
1DMF - your code looks as if it has been adapted from something using similar functionality to word:

- the "wdPrintAllDocument" constant is Word based.
- there are comments that refer to closing Word

Still, you have a working solution now, so not to worry.

John
 
Yes I was playing with another function I wrote for printing word docs, i have similar for publisher, excel etc..

It was an oversight not changing some comments and I wasn't sure if the wdPrintAllDocument would work either, but as the function bombed at trying to create the object, I never got to find out if any of the other MS application methods for printing would work.

After exhaustive hunting I found that link to a working method and even they made a comment about how stupidly difficult it is to print an exisitng PDF via VBA.

I still have the problem that it seems to leave Acrobat open even though it closes the actual document after printing it.

Howeveer, the end user is happy with the overall functionality and it's a minor inconveience having to manually close Acrobat.





"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top