visual basic .net shell command with word

Posted on 2004-11-27
Last Modified: 2013-11-25

i have written a piece of code that when a button is clicked it opens up microsoft word:

        Dim retval
        Dim Hideshow As String
        Hideshow = "Hiding and Showing forms.txt"
        retval = Shell("C:\program files\Microsoft Office\OFFICE11\winword.exe " & Hideshow)

but im not sure if everyones microsoft word .exe will be in the same place, is there anyway to get round this probelm so that everyone will be able to open it with word?


Question by:garypyne
    LVL 48

    Accepted Solution

    if you're trying to open a .doc file, in .NET (VB.NET), you can try like:

    'Start Document
        Public Function startDoc(ByVal filepath As String, Optional ByVal args As String = "") As Boolean
                System.Diagnostics.Process.Start(filepath, args)
                Return True
            Catch ex As Exception
                Return False
            End Try
        End Function

    call like:



    startDoc("C:\program files\Microsoft Office\OFFICE11\winword.exe", Hideshow)

    else you will need to use the Word Automation Objects instead.
    LVL 69

    Expert Comment

    by:Éric Moreau
    don't give the full path (just winword.exe). it will be found.
    LVL 69

    Expert Comment

    by:Éric Moreau
    The comment of ryancys applies only to VB.Net.

    My suggestion: points to emoreau
    LVL 69

    Expert Comment

    by:Éric Moreau
    ryancys comment is for VB.Net only. The code posted by the asker is VB6. It is defintely not solving the problem!
    LVL 48

    Expert Comment

    by:Ryan Chong
    I can post a VB6 solution that launch word document regardless of where the M$ Word was installed, but it's not meaningful since asker is not responding to this question.

    My suggestion: give points to emoreau as he's posted the comment that more suitable for the above question.

    LVL 69

    Expert Comment

    by:Éric Moreau
    PAQ_Man, is it worth adding comments on recommended disposition?
    LVL 48

    Expert Comment

    by:Ryan Chong
    oh.. just saw the question title itself did mentioned visual basic .net.... so ?? should we split the points instead, or ......

    i'm ok with final decision, cheers

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now