Hey,
I am trying to open a .dot file using a macro in Excel 2007.
Check out Microsoft's website for an example.
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
'open word doc
OpenWordDoc wdApp, wdDoc
Sub OpenWordDoc(wdApp, wdDoc)
'In order to use this code you must set a reference to the
'Word object library by doing this. In the VB Editor click
'Tools, References. Then search for Microsoft Word n.n Object Library
'where n.n will depend on your version of Word.
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDoc = wdApp.Documents.Open("C:\Documents and Settings\joe\Desktop\template.dot")
wdApp.Visible = True
'You can now do whatever you like with the Word document e.g.
'wdDoc.PrintOut
'wdDoc.SaveAs "C:\temp\hello.doc"
'wdDoc.Activate
'etc
End Sub
The code breaks at:
I get the following error:
Run-time error '-2147023170 (8007J6be)':
Automation error
The remote procedure call failed.
I believe the code works fine in 2003, but not in 2007.
In order to get it to work, I need to open the template.dot file first and then run the macro.
I'm using the following references:
- Visual Basic For Applications
- Microsoft Excel 12.0 Object Library
- OLE Automation
- Microsoft Office 12.0 Object Library
- Microsoft Forms 2.0 Object Library
- Microsoft Word 12.0 Object Library
Any ideas?
Bookmarks