Problem opening a word file from Excel

  • Thread starter Thread starter gromit12
  • Start date Start date
G

gromit12

Hi,

Just trying to open a Word file from Excel. The code below compiles
OK, and gets as far as opening Word, but then a dialog box pops open
with this:

Run-time error '-2147417851 (80010105)':
Automation Error
The server threw an exception.

I have both Office 2000 and 2007 installed on XP. Any ideas what could
be causing this?

Cheers
Gromit

=========================

Sub test()
Dim sPath As String
Dim sDoc As String
Dim objWord As Word.Application
Set objWord = New Word.Application

sPath = Application.ThisWorkbook.Path
sDoc = sPath & "\testform.doc"

With objWord
.Visible = True
.Activate
.WindowState = wdWindowStateMaximize
.Documents.Open Filename:=sDoc
End With

End Sub
 
Some thoughts...
1. Do you have a reference set to the Word application in Tools | References?
2. If the Workbook with the code is a new unsaved workbook then
no file path will exist.
3. Do you really store your Word docs and Excel files in the same folder?
4. Its generally good practice with automation to use the correct reference
for objects and to use numeric values for constants...

sPath = Excel.Application.ThisWorkbook.Path

.WindowState = 1
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"gromit12" <[email protected]>
wrote in message
Hi,
Just trying to open a Word file from Excel. The code below compiles
OK, and gets as far as opening Word, but then a dialog box pops open
with this:
Run-time error '-2147417851 (80010105)':
Automation Error
The server threw an exception.
I have both Office 2000 and 2007 installed on XP. Any ideas what could
be causing this?
Cheers
Gromit
======================

Sub test()
Dim sPath As String
Dim sDoc As String
Dim objWord As Word.Application
Set objWord = New Word.Application

sPath = Application.ThisWorkbook.Path
sDoc = sPath & "\testform.doc"

With objWord
.Visible = True
.Activate
.WindowState = wdWindowStateMaximize
.Documents.Open Filename:=sDoc
End With
End Sub
 
Jim Cone said:
Some thoughts...
1. Do you have a reference set to the Word application in Tools | References?
2. If the Workbook with the code is a new unsaved workbook then
no file path will exist.
3. Do you really store your Word docs and Excel files in the same folder?
4. Its generally good practice with automation to use the correct reference
for objects and to use numeric values for constants...

sPath = Excel.Application.ThisWorkbook.Path

.WindowState = 1
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"gromit12" <[email protected]>
wrote in message
Hi,
Just trying to open a Word file from Excel. The code below compiles
OK, and gets as far as opening Word, but then a dialog box pops open
with this:
Run-time error '-2147417851 (80010105)':
Automation Error
The server threw an exception.
I have both Office 2000 and 2007 installed on XP. Any ideas what could
be causing this?
Cheers
Gromit
======================

Sub test()
Dim sPath As String
Dim sDoc As String
Dim objWord As Word.Application
Set objWord = New Word.Application

sPath = Application.ThisWorkbook.Path
sDoc = sPath & "\testform.doc"

With objWord
.Visible = True
.Activate
.WindowState = wdWindowStateMaximize
.Documents.Open Filename:=sDoc
End With
End Sub

Same thing happened with Office 97 / Office 2000:

http://support.microsoft.com/kb/242375

Suggested workaround is to use late binding.

HTH
 
Back
Top