Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Error opening Word document from Excel VBA code

I am trying to upgrade from Office 2003 to Office 2007. One problem I am
having is opening a Word document from Excel VBA code. It works fine in 2003
version but not in 2007 version.
Here's the code:
-----
Sub OpenMyDocument()
Dim myDoc As String
myDoc = [full path name of my document in quotes]

Dim myDocument As Document

Set myDocument = Documents.Open(myDoc)
MsgBox "opened"
myDocument.Close
MsgBox "closed"

Set myDocument = Nothing
End Sub
-----

I added a reference to "Microsoft Word 11.0 Object Library" for the Excel
2003 version which automatically becomes "Microsoft Word 12.0 Object Library"
for the Excel 2007 version.

The error I recieve is: "Run-time error '429': ActiveX component can't
create object" and occurs at the Documents.Open() command. I'm guessing it
chokes on opening the word document.

Anyone have any suggestions for correcting this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Error opening Word document from Excel VBA code

"engineer_rich" wrote:

I am trying to upgrade from Office 2003 to Office 2007. One problem I am
having is opening a Word document from Excel VBA code. It works fine in 2003
version but not in 2007 version.
Here's the code:
-----
Sub OpenMyDocument()
Dim myDoc As String
myDoc = [full path name of my document in quotes]

Dim myDocument As Document

Set myDocument = Documents.Open(myDoc)
MsgBox "opened"
myDocument.Close
MsgBox "closed"

Set myDocument = Nothing
End Sub
-----

I added a reference to "Microsoft Word 11.0 Object Library" for the Excel
2003 version which automatically becomes "Microsoft Word 12.0 Object Library"
for the Excel 2007 version.

The error I recieve is: "Run-time error '429': ActiveX component can't
create object" and occurs at the Documents.Open() command. I'm guessing it
chokes on opening the word document.

Anyone have any suggestions for correcting this?


Try creating Word.Application object first, then use appWord.Documents.Open:

Sub OpenMyDocument()

Dim myDoc As String
myDoc = "c:\scripts\test.doc"

Dim appWord As New Word.Application
Dim myDocument As Word.Document

Set myDocument = appWord.Documents.Open(myDoc)
MsgBox "opened"
myDocument.Close
MsgBox "closed"

Set myDocument = Nothing

End Sub

--
urkec
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Error opening Word document from Excel VBA code

Thank you!

That worked perfectly.

I did add a:
Set appWord = Nothing
at the end to clean up a little.

Thanks again!!

"urkec" wrote:

"engineer_rich" wrote:

I am trying to upgrade from Office 2003 to Office 2007. One problem I am
having is opening a Word document from Excel VBA code. It works fine in 2003
version but not in 2007 version.
Here's the code:
-----
Sub OpenMyDocument()
Dim myDoc As String
myDoc = [full path name of my document in quotes]

Dim myDocument As Document

Set myDocument = Documents.Open(myDoc)
MsgBox "opened"
myDocument.Close
MsgBox "closed"

Set myDocument = Nothing
End Sub
-----

I added a reference to "Microsoft Word 11.0 Object Library" for the Excel
2003 version which automatically becomes "Microsoft Word 12.0 Object Library"
for the Excel 2007 version.

The error I recieve is: "Run-time error '429': ActiveX component can't
create object" and occurs at the Documents.Open() command. I'm guessing it
chokes on opening the word document.

Anyone have any suggestions for correcting this?


Try creating Word.Application object first, then use appWord.Documents.Open:

Sub OpenMyDocument()

Dim myDoc As String
myDoc = "c:\scripts\test.doc"

Dim appWord As New Word.Application
Dim myDocument As Word.Document

Set myDocument = appWord.Documents.Open(myDoc)
MsgBox "opened"
myDocument.Close
MsgBox "closed"

Set myDocument = Nothing

End Sub

--
urkec

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Error opening Word document from Excel VBA code

"engineer_rich" wrote:

Thank you!

That worked perfectly.

I did add a:
Set appWord = Nothing
at the end to clean up a little.


Sorry, I also forgot to quit Word.Application:

....

appWord.Quit
Set appWord = Nothing


--
urkec
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
Opening word document through excel vba srinums Excel Discussion (Misc queries) 0 June 8th 06 12:02 PM
Opening a Word and/or PDF document from Excel Vikesh Jain Excel Programming 1 November 29th 05 11:51 AM
Opening Word Document with excel [email protected] Excel Discussion (Misc queries) 0 March 21st 05 01:49 AM
opening a word document from excel chris Excel Programming 5 April 1st 04 03:17 PM
Opening a Word Document in Excel Tonja Excel Programming 2 September 18th 03 02:56 AM


All times are GMT +1. The time now is 11:36 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"