Results 1 to 5 of 5

Thread: How to execute file by file extension

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    2
    Hi
    I am new to V.B and would be gratefule for any help/advice with my first VB project.
    How to automatically start Acrobat Reader when user clicks on the command button and the.PDF file opens up.

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    put a text box and a command buttom on a form and copy this code into the declarations section of the form

    type the filenem into the text box and click the command button

    Code:
    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 Sub Command1_Click()
    Call ShellExecute(0&,vbNullString,text1.Text, vbNullString, _
    vbNullString, vbNormalFocus)
    End Sub
    Mark
    -------------------

  3. #3
    Junior Member
    Join Date
    May 2000
    Location
    Oporto - Portugal
    Posts
    16

    Question ListBox

    Originally posted by Mark Sreeves
    put a text box and a command buttom on a form and copy this code into the declarations section of the form

    type the filenem into the text box and click the command button

    Code:
    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 Sub Command1_Click()
    Call ShellExecute(0&,vbNullString,text1.Text, vbNullString, _
    vbNullString, vbNormalFocus)
    End Sub
    hi mark

    And with a dbclick() in a listbox?? i put list1.text and it doesn´t work

    thanks

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    2

    Thumbs up

    Thanks Mark

    i just had to enter this.

    Private Sub Command1_Click()
    Dim RetVal
    RetVal = ShellExecute(Form2.hwnd, "open", _
    "\Email+V5\Docs\network.pdf", "", "\Docs", SW_RESTORE)

    End Sub

    Because the .pdf files will reside on the CD-ROM
    the only way it would work was after i entered
    Dim RetVal= shellExecute in the Command1_Click.

  5. #5
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    fmnunes

    fmnunes, this works for me!

    Code:
    Option Explicit
    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 Sub Form_Load()
    List1.AddItem "C:\Acrobat3\Reader\Acrobat.pdf"
    List1.AddItem "C:\Acrobat3\Reader\License.pdf"
    
    
    End Sub
    
    Private Sub List1_DblClick()
    Dim filename As String
    
    filename = List1.Text
    
    Call ShellExecute(0&, vbNullString, filename, vbNullString, _
    vbNullString, vbNormalFocus)
    End Sub
    Mark
    -------------------

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