Results 1 to 6 of 6

Thread: Running Outside Application

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    12

    Question

    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??

  2. #2
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    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]

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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.

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Oops gwdash beated me
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    12
    THANKS FOR THE HELP!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width