TheSwamp
Code Red => VB(A) => Topic started by: krampaul82 on June 07, 2010, 02:17:20 PM
-
How do I open a .pdf file from a Visual Basic Program?
any help appreciated...
-
Open it as open adobe to view it or open it as open it in VBA to do something with it?
Prior is something like this:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Public Function OpenFile(ByVal FileName As String) As Long
OpenFile = ShellExecute(0, "Open", FileName, "", "C:\", 1)
End Function
latter isn't gonna happen without some knowledge of the PDF structure and/or a type library and/or a class for handling PDF files.
-
I would like to press a command button and have it open an adobe pdf file for printing
-
well, that will do it, just pass the file name to the function and it will open the PDF in adobe
-
using your example above how would i pass the filename to this function?
(at your convienence.....)
-
OpenFile "filenamegoeshere"
That simple
-
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Public Function OpenFile(ByVal FileName As String) As Long
OpenFile = ShellExecute(0, "Open", FileName, "", "C:\ALL_pdf_Cut_Sheets\Actuators\", 1)
End Function
like this?
sub file_get
OpenFile "ms8105a1008"
End Sub
-
that should do it, but you might need to include the path to the file as well. All I can suggest it to try it
-
No Dice... :|
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Public Function OpenFile(ByVal FileName As String) As Long
OpenFile = ShellExecute(0, "Open", FileName, "", "C:\ALL_pdf_Cut_Sheets\Actuators\", 1)
End Function
like this?
sub file_get
OpenFile "C:\ALL_pdf_Cut_Sheets\Actuators\ms8105a1008"
End Sub
-
you need to include the file extension ..
Try this:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Public Function OpenFile(ByVal FileName As String) As Long
OpenFile = ShellExecute(0, "Open", FileName, "", "C:\ALL_pdf_Cut_Sheets\Actuators\", 1)
End Function
Sub file_get()
OpenFile "C:\ALL_pdf_Cut_Sheets\Actuators\ms8105a1008.pdf"
End Sub
In your form, make the action of the click event for your button call file_get
-
Suh-Wheet that was it. Thanks for sticking with me Keith.
-
no problem
-
For print Try with verb "print" (parameter lpOperation)
ShellExecute(0, "print",....