How to print an external file?

  • Thread starter Thread starter Douglas J. Steele
  • Start date Start date
D

Douglas J. Steele

Unfortunately, there isn't one approach that's guaranteed to work for all
files, since each file uses a different program to print it, and each
program can require different instructions to make it work.
 
It would be great if I could at least find the approach to print a .pdf
file. Is there any source to read and learn about this feature?
Million thanks
 
Hi,
Just in case you haven't found a sample yet, here's a sub that should print any document:

Public Sub PrintThisFile(hWnd As Long, FileName As String)
Dim X As Long
X = ShellExecute(FormName, "Print", FileName, vbNullString, 0&, SW_SHOWNORMAL)
End SubYou can call it from a form like:PrintThisFile Me.hWnd, "C:\somedoc.pdf"Also, put this code in the Declarations section of a
standard module:Public Const SW_SHOWNORMAL = 1Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal
hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal
nShowCmd As Long) As Long
I have not tested this out!!
 
Shell Chr(34) & "FullPathToAcrobat.exe" & Chr(34) & " /p /h " & _
Chr(34) & "FullPathToPDFFile" & Chr(34), vbMinimizedFocus

will print to the default printer. Remove the "/h " if you want to present
the Print Dialog to the user.
 
Hi
I just don't know how to thank you for your great help. And I hope you don't
mind if I add one more question. I followed your instructions and it worked
perfectly. I just didn't understand what hWind was. To find out what it does
I omitted it from your code and used it this way:

-------------------------------------------------------------------------------
Public Sub PrintThisFile(FileName As String)
Dim X As Long
X = ShellExecute(FormName, "Print", FileName, vbNullString, 0&,
SW_SHOWNORMAL)
end sub

PrintThisFile "C:\somedoc.pdf"
--------------------------------------------------------------------------------
Still the code prints the file without any difference.


Thank you very much for any kind of explanation

with regards
Ghalamkari
 
Thank you for your sample code. I was able to print a pdf file using your
suggested sample.

I appreciate your help.
 
Any kind of help/hint is much appreciated for solving this problem.

I have a table in a access database which contains the name of different
parts of a huge machine and the drawings that concern that mechanical part.
I'm trying to print some .pdf - .xls and .doc files when a user clicks
"Print" button on a search result form. All files are saved to specific
folders in a drive.

here is an example:
the user searches for this part : ABCDE and a list of all the drawings and
documents of this part is shown. Now I'm trying to print ABCDE.pdf and
ABCDE.xls and ABCDE.doc by clicking a button.

Thanks for any possible advice.
 
I'm so sorry. I didn't intend to stay on the top. It seems I have a problem
with my time settings.
 
Back
Top