Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / February 2006

Tip: Looking for answers? Try searching our database.

Run Word macro from Access

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wes - 17 Feb 2006 20:32 GMT
First post, please be kind.

Have just dived into the world of VBA, quite facinating I must say. Have
found this board VERY useful. I have searched for answers to my problems and
have always found the answers, but not for this one, even though there are
numerous post concerning this very subject.

So here we go...

Have written a Macro in Word, it works just fine.

Have written VBA code in Access, it works just fine.

Would like to call/run the Word Macro from Access and then continue on with
my Access code, my head hurts from banging it against a brick wall trying to
figure this out.

Here is what I have so far in Access to call/run the Word Macro.

Sub Word_Macro()

   Dim myWD As Object
   Dim myFile As Object
   Set myWD = CreateObject("Word.Application")
   Set myFile = myWD.Documents.Open("c:\mypath\config sfs macro.doc")
   myWD.Run "SFs_ConfigHeader"
   myFile.Close
   myWD.Quit
   Set myFile = Nothing
   Set myWD = Nothing

End Sub

All works well until I get to - myFile.Close-, I am then treated to a very
nasty error box that states "Run-Time error '462': The remote Server Machine
does not exist or is unavailable".

Have gone into Access and made Word objects available ( I think, pretty sure
I did, yeah, I did, I think). Just so yall know.

Some help would be appreciated.

wes
John Nurick - 18 Feb 2006 09:52 GMT
At a guess the problem is arising because    
 myfile.Close
is telling Word to close the document, and Word is popping up a
messagebox to ask whether or not you want to save the changes [it
thinks] your macro made. But because the instance of Word is not visible
you aren't seeing and can't respond to the messagebox.

Check in Word VBA help for the Document's Close method: IIRC you use
    myFile.Close True
or   
    myFile.Close False
according to whether you want to save the changes.

If your Word macro uses the Selection object, you may well find that it
doesn't work properly if the document window is not visible. When
automating Word and Excel, it's best to avoid using Selection wherever
possible: instead, work with the specific objects exposed by the object
model (e.g. Ranges and Shapes).

Also, if the macro opens or creates any other documents, they need to be
closed (with or without saving) before you do
    myWD.Quit
or you'll get the same trouble.  

>First post, please be kind.
>
[quoted text clipped - 39 lines]
>
>wes

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
Wes - 18 Feb 2006 15:39 GMT
Found it! It was in the Word macro. To be more specific, while trying to get
it running I had added "Application.Quit" to the Word Macro (I had three
instances of Word, according to task manager, at one point). Had to learn how
to open "objects" then close them.

I really need to buy a book or go to a class on VB.

Anyway, I took that line out of the Word Macro, now all works well.

This is a great board, have really learned alot just reading and searching.

Thanks to all those that have posted!

Thanks to John for your reply!

wes
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.