Results 1 to 3 of 3

Thread: How can I open a file with a command button?

  1. #1

    Thread Starter
    Junior Member rastin's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    26

    Question How can I open a file with a command button?

    Hi,
    I would like to open up a MS Word Document (or another file) by clicking on a command button.

    Can anyone please tell me what code can I put in the command button for this?

    I don't wish to use the OLE function.

    Rastin

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Use the ShellExecute API function.
    Put the following in the General Declaration section of your form.
    VB Code:
    1. Private Declare Function ShellExecute _
    2.  Lib "shell32.dll" Alias "ShellExecuteA" ( _
    3.  ByVal hwnd As Long, _
    4.  ByVal lpOperation As String, _
    5.  ByVal lpFile As String, _
    6.  ByVal lpParameters As String, _
    7.  ByVal lpDirectory As String, _
    8.  ByVal nShowCmd As Long) As Long
    Then in the click event of a button use code simular to this:
    VB Code:
    1. Private Sub Command1_Click()
    2.     ShellExecute Me.hwnd, "Open", "c:\TheFileToOpen.doc", "", "", vbNormalFocus
    Best regards

  3. #3
    Megatron
    Guest
    Another method would be to shell WinWord and pass the filename as the command line argument, e.g.
    Code:
    Shell "Winword myfile.doc", 1

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