• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

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?
0
Sparky191
Asked:
Sparky191
5 Solutions
 
EDDYKTCommented:
Several way you can do.
1. check registry
2. check progid


ie

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
Do
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
0
 
Ryan ChongCommented:
or try like:

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

then..

msgbox "Is Word installed? > " & isWordInstalled

cheers
0
 
Erick37Commented:
*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
    'Failed
    Unload Me
Else
    'Use Word here
End If
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Sparky191Author Commented:
The trapping looks like being the best way. I'll try it tomorrow and let you know how I get one.
0
 
--laser--Commented:
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.

eg.

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
0
 
Erick37Commented:
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.
0
 
atheekurrahmanCommented:
Hi,
 vat about this

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



Atheek
0
 
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.
0
 
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.
0
 
Erick37Commented:
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
0
 
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.
0
 
Erick37Commented:
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."

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vafctCreateObject.asp
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now