Results 1 to 5 of 5

Thread: Opening Files

  1. #1
    Guest
    I need to write an app that prompts the user with an open dialog box. after the user Selects the file, I need to open it. I know how to use the common dialog ShowOpen method, How do I open the file in its respective app. I have no way of knowing the file types in advance. Please help.
    thanks,
    Brian

  2. #2
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Hello BG!

    Here is my chance to help you.

    With the filename from the commondialog use it with the API ShellExecute.

    Code:
    Call ShellExecute(GetActiveWindow(), "Open", "Filename.doc", vbNullString, CurDir(), SW_SHOWNORMAL)
    Chemically Formulated As:
    Dr. Nitro

  3. #3
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633

    Here is a more complete version!

    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 Const SW_SHOWNORMAL = 1
    Private Const SW_SHOWMINIMIZED = 2
    Private Const SW_SHOWMAXIMIZED = 3
    Private Const SW_SHOW = 5
    Private Const SW_MINIMIZE = 6
    Private Const SW_SHOWMINNOACTIVE = 7
    Private Const SW_SHOWNA = 8
    Private Const SW_RESTORE = 9
    Private Const SW_SHOWDEFAULT = 10
    
    Private Sub Command1_Click()
      Call ShellExecute(Me.hwnd, "Open", "Hello.doc", vbNullString, vbNullString, SW_SHOWNORMAL)
    End Sub
    Chemically Formulated As:
    Dr. Nitro

  4. #4
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633

    One more thing.

    To get the filename after selecting the file, it will be store in "CommonDialog1.Filename". This will include the extention and you can plug it straight into the API.
    Chemically Formulated As:
    Dr. Nitro

  5. #5
    Guest

    Thumbs up

    Right On! thanks alot

    Brian

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