Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default Microsoft Word Object Library in Excel

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.
  #2   Report Post  
Posted to microsoft.public.excel.misc
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.


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default Microsoft Word Object Library in Excel

I did find code similar to what you've given me on a web site. Wheter it's
that one or the code you've given me, it seems that it doesn't work if I
don't set a reference to the Microsoft Word Object Library. The code results
in an error at the line "Documents.Open (myPath & myFile)".

Would you know why?

....some code before

Set wordApp = CreateObject("Word.Application")
If Err.Number < 0 Then
MsgBox "Please contact your file administrator."
Exit Sub
End If

myPath = "D:\Test\Actions To Complete\"
myFile = Dir(myPath & "*.doc")

Do While myFile < ""
With wordApp
Documents.Open (myPath & myFile)
strDate = ActiveDocument.Tables(1).Rows(1).Cells(2).Range.Te xt
strDate = Left(strDate, Len(strDate) - 2)
End With
Cells(X, 2) = strDate
myFile = Dir
Loop

....some code after


"Jim Rech" wrote:

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.



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,718
Default Microsoft Word Object Library in Excel

I don't see a dot before Documents.Open. Without it the With wordApp does
nothing.

With wordApp
.Documents.Open (myPath & myFile)



--
Jim
"Gaetan" wrote in message
...
|I did find code similar to what you've given me on a web site. Wheter it's
| that one or the code you've given me, it seems that it doesn't work if I
| don't set a reference to the Microsoft Word Object Library. The code
results
| in an error at the line "Documents.Open (myPath & myFile)".
|
| Would you know why?
|
| ...some code before
|
| Set wordApp = CreateObject("Word.Application")
| If Err.Number < 0 Then
| MsgBox "Please contact your file administrator."
| Exit Sub
| End If
|
| myPath = "D:\Test\Actions To Complete\"
| myFile = Dir(myPath & "*.doc")
|
| Do While myFile < ""
| With wordApp
| Documents.Open (myPath & myFile)
| strDate =
ActiveDocument.Tables(1).Rows(1).Cells(2).Range.Te xt
| strDate = Left(strDate, Len(strDate) - 2)
| End With
| Cells(X, 2) = strDate
| myFile = Dir
| Loop
|
| ...some code after
|
|
| "Jim Rech" wrote:
|
| 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.
|
|
|


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default Microsoft Word Object Library in Excel

Aaahhhh... I can sleep now... thanks to you!

"Jim Rech" wrote:

I don't see a dot before Documents.Open. Without it the With wordApp does
nothing.

With wordApp
.Documents.Open (myPath & myFile)



--
Jim
"Gaetan" wrote in message
...
|I did find code similar to what you've given me on a web site. Wheter it's
| that one or the code you've given me, it seems that it doesn't work if I
| don't set a reference to the Microsoft Word Object Library. The code
results
| in an error at the line "Documents.Open (myPath & myFile)".
|
| Would you know why?
|
| ...some code before
|
| Set wordApp = CreateObject("Word.Application")
| If Err.Number < 0 Then
| MsgBox "Please contact your file administrator."
| Exit Sub
| End If
|
| myPath = "D:\Test\Actions To Complete\"
| myFile = Dir(myPath & "*.doc")
|
| Do While myFile < ""
| With wordApp
| Documents.Open (myPath & myFile)
| strDate =
ActiveDocument.Tables(1).Rows(1).Cells(2).Range.Te xt
| strDate = Left(strDate, Len(strDate) - 2)
| End With
| Cells(X, 2) = strDate
| myFile = Dir
| Loop
|
| ...some code after
|
|
| "Jim Rech" wrote:
|
| 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.
|
|
|



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB Error Object Library Not Registered Karine Rivet Excel Discussion (Misc queries) 2 April 11th 06 07:13 PM
Change individual cell heights/widths in Microsoft Excel 2000 like Microsoft Word urbanplanner Excel Discussion (Misc queries) 3 December 7th 05 03:57 PM
missing object library eagle7 Excel Discussion (Misc queries) 2 November 6th 05 04:06 AM
How to check Solver and Forms 2.0 Object Library permanently? yoyo2000 Excel Discussion (Misc queries) 1 September 26th 05 03:04 AM
Object library missing Nigel Excel Discussion (Misc queries) 1 May 5th 05 05:46 PM


All times are GMT +1. The time now is 04:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"