Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. | | | |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
VB Error Object Library Not Registered | Excel Discussion (Misc queries) | |||
Change individual cell heights/widths in Microsoft Excel 2000 like Microsoft Word | Excel Discussion (Misc queries) | |||
missing object library | Excel Discussion (Misc queries) | |||
How to check Solver and Forms 2.0 Object Library permanently? | Excel Discussion (Misc queries) | |||
Object library missing | Excel Discussion (Misc queries) |