View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default Microsoft Word Object Library in Excel

There are two ways to run Word from Excel: Early binding (by setting a
reference) or late binding (not setting a reference).

When you don't know if Word is not the target machine use late binding
because it allows you to trap the error that occurs if Word is not
installed:

Sub RunWordFromXL()
Dim oWord As Object
Dim oDoc As Object
On Error Resume Next
Set oWord = CreateObject("Word.Application")
If Err.Number < 0 Then
MsgBox "Word not installed or would not start"
Else
oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Add
oDoc.Range.Text = "Hi"
End If
End Sub

Remember: Do NOT set a reference to Word.

--
Jim
"Gaetan" wrote in message
...
| Hi everyone,
|
| I need to run VBA codes in Excel that uses the Microsoft Word Object
| Library. If the object lbrary is not loaded, the code won't work properly
and
| causes unfortunate problems. Because the code can be run on any given
| machine, there's no way for me to know if the object library has been
loaded
| on that machine.
|
| Is there a way, using VBA, to load this object library before the code
runs,
| or at least to know whether or not the library is loaded so that I can
advise
| the user if it's not?
|
| Thanks for your help.