Running a doc file from VB6

Hi all,

What is the easiest way to run a .doc file from a VB6 app I know how to launch the Word Viewer with a document and I know how to access Word if it is installed on the user's machine. What I want to do is have a line of code that calls a document with the ".doc" extension and then opens the document in whatever program (Word, WordPad, WordPerfect, etc.) is associated with that extension.

Is this possible

Thansk in advance for your help!



Answer this question

Running a doc file from VB6

  • Andy Simonds

    Hi,

    You will need to use the Win32 API to achieve that. The ShellExecute API function provides this functionality.

    Example:
    http://pinvoke.net/search.aspx search=shellexecute&namespace=[All]

    Regards,
    Vikram

  • Vlad R

    Hi!

    The folowing example opens a doc file:


    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
    Const SW_SHOW = 5

    Private Sub Command1_Click()
        ShellExecute hwnd, "open", "FILE NAME", vbNullString, "FILE DIRECTORY", SW_SHOW
    End Sub


    Hope it works...
    ------------------
    Best Regards,
    Alan



     



  • Running a doc file from VB6