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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open PDF file by clicking command button..(VB6) 1

Status
Not open for further replies.

yeeyin

Technical User
Jan 12, 2004
3
MY
hi, hope that someone can help me here..

i want to open User Manual which is PDF file by click a command button in the form. can anyone tell me the code? i am new in VB.. Thanks!

regards,
yeeyin
 
Try the Shell command (it's in VBHelp)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Forget Shell. You need to use ShellExecute to open any document with it's default app. eg. PDF with Acrobat Reader, .DOC with Word, .htm with IE etc.

This is the way I do it. There are neater ways, but I'm just Copy/Pasting from existing code.

In a module (.BAS), place all of this:

'************************

Option Explicit

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private 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

Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10
Private Const SE_ERR_NOASSOC As Long = 31

Public Sub RunShellExecute(sTopic As String, _
sFile As Variant, _
sParams As Variant, _
sDirectory As Variant, _
nShowCmd As Long)

Dim hWndDesk As Long
Dim success As Long

'the desktop will be the
'default for error messages
hWndDesk = GetDesktopWindow()

'execute the passed operation
success = ShellExecute(hWndDesk, sTopic, sFile, sParams, sDirectory, nShowCmd)

'This is optional. Uncomment the three lines
'below to have the "Open With.." dialog appear
'when the ShellExecute API call fails
If success = SE_ERR_NOASSOC Then
Call Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " & sFile, vbNormalFocus)
End If

End Sub

'*********************************

Create a form, place a button called Command1 on it and paste in this code into the declarations area:

'*********************************

Dim startpath As String
Dim sTopic As String
Dim sFile As String
Dim sParams As Variant
Dim sDirectory As Variant

Private Sub Command1_Click()
sFile = "C:\PDFs\Myfile.pdf"
sTopic = "Open"
sParams = 0&
sDirectory = 0&

Call RunShellExecute(sTopic, sFile, sParams, sDirectory, 1)

End Sub

'end of code.

Replace the sFile variable with whatever you want.

Hope that helps.

Stu.

 
Thanks for help~!!
thanks a lot..!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top