I am a beginner to VB, and am trying to figure out how to open an Adobe Acrobat (.pdf). All I want to do is press a button, and the (.pdf) opens.
Any suggestions??
Printable View
I am a beginner to VB, and am trying to figure out how to open an Adobe Acrobat (.pdf). All I want to do is press a button, and the (.pdf) opens.
Any suggestions??
You cab do this with the ShellExecute API:
NOTE:This code is NOT mine, it's from vbapi.com
Code:
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public 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
Public Const SW_RESTORE = 9
' Place the following code inside window Form1. ***
Private Sub Command1_Click()
Dim retval As Long ' return value
'Open the document:
retval = ShellExecute(Form1.hWnd, "open", "C:\Project\myfile.pdf", "", "C:\Project\", SW_RESTORE)
End Sub
You should use the ShellExecute Api to open a file with it's default program:
have fun!Code:'Put this in a module
Public 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
'Open a file with it's default program
Public Sub Execute(file As String)
lngResult = ShellExecute(hWnd, "Open", file, "", "", vbNormalFocus)
End Sub
'In a form:
Call Execute("c:\MyFile.pdf")
:eek: Oops gwdash beated me :(
Here is an easy way... but it requires the reader to be in the same place on every computer your run it on:
however the best way is to use the shellexecute api as follows:Code:Private Sub Command1_Click()
Shell "C:\PROGRA~1\ADOBE\ACROBA~1.0\READER\ACRORD32.EXE d:\readme.pdf"
End Sub
Add the following to a module:
Add this code to your button (all you need to change is the "readme.pdf" part:Code:Public 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
Code:Private Sub Command2_Click()
ShellExecute hwnd, "open", "d:\readme.pdf", vbNullString, CurDir$, SW_SHOW
End Sub
THANKS FOR THE HELP!!