PDA

View Full Version : Printing a .pdf file



francozola25
08-19-2008, 08:20 AM
Hello

I was wondering if someone could help me.

I wanto print off a .pdf file as part of a dropdown variable but it doesn't seem to work

Note: the file is already in .pdf so there is not need to convert from word before hand.

I have a combobox on a userform that display the filename contents of a folder:

This is the code for combobox


Private Sub UserForm_Initialize()
'Files in folder listed in Listbox1
Dim FSO As Object, fld As Object, Fil As Object
Dim SubFolderName As String
Dim i As Integer
Set FSO = CreateObject("Scripting.FileSystemObject")
Me.ComboBox1.Clear 'clear previous entries
SubFolderName = "\\myserver\Documents (file://\\myserver\Documents)"
Set fld = FSO.GetFolder(SubFolderName)
For Each Fil In fld.Files
i = i + 1
Me.ComboBox1.AddItem Fil.Name

Next Fil
End Sub


the insert button is pressed along with other fields complete. What i want to do then is to open the ComboBox1 pdf file and print it off but it doesn't seem to work

sbrbot
08-19-2008, 10:15 AM
What? You want to open and print PDF document from VBA!? Can you open PDF document in Word? I don't think so. Hence, how could you do that in VBA?

Nelviticus
08-20-2008, 01:23 AM
You can do this, but you need to hard-code the path to Acrobat.exe and re-write it if you install a different version:
Shell ("""C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Acrobat.exe"" /p /h ""C:\Temp\Document1.pdf""")
Also it will leave Acrobat open.

Regards

sbrbot
08-20-2008, 09:13 AM
OK, this is calling external Adobe Acrobat to print this file, it is not printed from Word. However, for using this technique you can read Windows registry to find out what is the path to Acrobat Reader (in HKLM\SOFTWARE\Adobe\Acrobat Reader\9.0\InstallPath there is InstallPath key defining what is the path of Acrobat Reader, of course you cannot rely on that customer has 9.0 version of Reader) but I'm not sure if all this is needed. Finally you can offer customer a Browse button to select Acrobat Reader for printing docs. But as said at the beginning, Word does not work with PDF docs directly (at the moment, we'll se tommorow).