Using VB6 how can I check if Word is installed?

How can I check if word is installed before I try to create a word object in VB?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Several way you can do.
1. check registry
2. check progid


Option Explicit

Private Declare Function CLSIDFromProgID Lib "ole32.dll" (ByVal _
lpszProgID As Long, pCLSID As Any) As Long
Private Declare Function StringFromCLSID Lib "ole32.dll" (pCLSID As _
Any, lpszProgID As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias _
"RtlMoveMemory" (dest As Any, source As Any, ByVal bytes As Long)
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
' Convert a ProgID (such as "Word.Application") into the
' string representation of its CLSID
Function ProgIdToCLSID(ByVal ProgID As String) As String
Dim pResult As Long, pChar As Long
Dim char As Integer, length As Long
' No need to use a special UDT
Dim guid(15) As Byte

' get the CLSID in binary form
CLSIDFromProgID StrPtr(ProgID), guid(0)
' convert to a string, get pointer to result
StringFromCLSID guid(0), pResult
' find the terminating null char
pChar = pResult - 2
pChar = pChar + 2
CopyMemory char, ByVal pChar, 2
Loop While char
' now get the entire string in one operation
length = pChar - pResult
' no need for a temporary string
ProgIdToCLSID = Space$(length \ 2)
CopyMemory ByVal StrPtr(ProgIdToCLSID), ByVal pResult, length
' release the memory allocated to the string
CoTaskMemFree pResult
End Function

Private Sub Command1_Click()

' return {00000000-0000-0000-0000-000000000000} if not found
Debug.Print ProgIdToCLSID("word.application")
End Sub
Ryan ChongCommented:
or try like:

Public Function isWordInstalled() As Boolean
    On Error GoTo EH
    Dim objApp As Object
    Set objApp = CreateObject("Word.Application")
    Set objApp = Nothing
    isWordInstalled = True
    Exit Function
    isWordInstalled = False
End Function


msgbox "Is Word installed? > " & isWordInstalled

*Assume* it is installed, and use error trapping to control program flow

On Error Resume Next

oWord = CreateObject("Word.Application")

If Err.Number <> 0 Then
    If Err.Number = 429 Then
        'Cannot create object
        MsgBox "Word is not available"
    End if
    Unload Me
    'Use Word here
End If

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Sparky191Author Commented:
The trapping looks like being the best way. I'll try it tomorrow and let you know how I get one.
did you try by checking if the application exists (like WINWORD.EXE) you can run a scan in the most common places that word would be installed for example "c:\program files\microsoft office\office10" and other places that users would install word to...obviously if the exe exists then word is installed.


Dim installed As Boolean
Dim exists As String
exists = Dir("c:\program files\microsoft office\office10\WINWORD.EXE", 0)
If exists = "WINWORD.EXE" Then installed = True Else installed = False
If installed = True Then MsgBox "word is installed" Else MsgBox "word is not installed"

if the file exists it will return "WINWORD.EXE" and if it dosnt exits it will return nothing
Be aware that CreateObject("Word.Application") will succeed when Word is available over the network (I believe), so it may no be a good test for local installation.
 vat about this

if len(dir("C:\Program Files\Microsoft Office\Office\WINWORD.EXE"))>0 then
end if

Sparky191Author Commented:
I think searching for the exe is bad practise myself. Catching via the error handler is a more concise and robust method in my opinion.
Sparky191Author Commented:
Erick37 - can you explain how you can make word availble over the network and how you can use VBA with a copy installed on the network and no locally.
In order to explicitly create an instance of Word located remotely, the servername must be specified.

Set oWord = CreateObject("Word.Application","\\TheServerName")
oWord.Visible = True
Sparky191Author Commented:
That seems to suggest that if you don't use the servername switch that the object creation will fail?

Didn't know you could run it from a server. Thats interesting.
From MSDN on the servername parameter:

"The name of the network server where the object will be created. If servername is an empty string (""), the local machine is used."
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.