Callling Word fronm Excel

  • Thread starter Duane Reynolds 322310
  • Start date
D

Duane Reynolds 322310

I am stumped. I am running the below code to print a mail merge. Excel stars
word , the mail merge macro in word runs and prints but Excel opens
debugger
and halts at .Documents.Open ("D:\Duane
Docs\Inspection_Report_browser_Merge2008_Fields.doc")
witrh the comment "Word can not open this file"
What am I missing here.
Thanks in advance
Duane

Sub ControlWordFromXL()


Dim objWord As Word.Application
'Set objWord = New Word.Application

With objWord
.Visible = True
.Activate
.WindowState = wdWindowStateMaximize
.Documents.Open ("D:\Duane
Docs\Inspection_Report_browser_Merge2008_Fields.doc")
End With
End Sub
 
J

Jim Cone

It worked for me after removing the comment ( ' ) in front of Set.
(I used a correct file path/file for my system)
Also, it is a good idea to set object variables to nothing when using automation...
Add this line just before End Sub...
Set objWord = Nothing
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Duane Reynolds 322310"
wrote in message
I am stumped. I am running the below code to print a mail merge.
Excel stars > word , the mail merge macro in word runs and prints
but Excel opens debugger and halts at .Documents.Open ("D:\Duane
Docs\Inspection_Report_browser_Merge2008_Fields.doc")

witrh the comment "Word can not open this file"
What am I missing here.
Thanks in advance
Duane

Sub ControlWordFromXL()


Dim objWord As Word.Application
'Set objWord = New Word.Application

With objWord
.Visible = True
.Activate
.WindowState = wdWindowStateMaximize
.Documents.Open ("D:\Duane
Docs\Inspection_Report_browser_Merge2008_Fields.doc")
End With
End Sub
 
D

Duane Reynolds 322310

It runs and executes just fine on my system but opens debug and highlights
that one line leaves excel open
Duane
 
J

Jim Cone

Re: "but opens debug and highlights that one line leaves excel open"

Huh...
What line?
There is nothing in your posted code that closes Excel, why wouldn't it still be open?
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"Duane Reynolds 322310"
wrote in message
It runs and executes just fine on my system but opens debug and highlights
that one line leaves excel open
Duane
 
D

Duane Reynolds 322310

Sorry next line after that sub is Application.quit but it stalls at
.Documents.Open ("D:\Duane
Docs\Inspection_Report_browser_Merge2008_Fields.doc") with this line
highlighted in yellow in debug.
 
J

Jim Cone

Your posted code should be all on one line (not two lines).
If that is not the problem then the file path and/or file name is probably incorrect.
'--
..Documents.Open ("D:\Duane Docs\Inspection_Report_browser_Merge2008_Fields.doc")
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Duane Reynolds 322310"
<[email protected]>
wrote in message
Sorry next line after that sub is Application.quit but it stalls at
.Documents.Open ("D:\Duane
Docs\Inspection_Report_browser_Merge2008_Fields.doc") with this line
highlighted in yellow in debug.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top