|
-
Oct 7th, 2000, 09:46 AM
#1
Thread Starter
New Member
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??
-
Oct 7th, 2000, 10:13 AM
#2
Fanatic Member
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
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Oct 7th, 2000, 10:14 AM
#3
Frenzied Member
You should use the ShellExecute Api to open a file with it's default program:
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")
have fun!
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 7th, 2000, 10:16 AM
#4
Frenzied Member
Oops gwdash beated me
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 7th, 2000, 10:17 AM
#5
Fanatic Member
Here is an easy way... but it requires the reader to be in the same place on every computer your run it on:
Code:
Private Sub Command1_Click()
Shell "C:\PROGRA~1\ADOBE\ACROBA~1.0\READER\ACRORD32.EXE d:\readme.pdf"
End Sub
however the best way is to use the shellexecute api as follows:
Add the following to a module:
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
Add this code to your button (all you need to change is the "readme.pdf" part:
Code:
Private Sub Command2_Click()
ShellExecute hwnd, "open", "d:\readme.pdf", vbNullString, CurDir$, SW_SHOW
End Sub
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Oct 7th, 2000, 08:30 PM
#6
Thread Starter
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|