Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a Word Macro from Excel ??

Status
Not open for further replies.

cresbydotcom

Technical User
May 22, 2006
234
Hi

I asked the question in another thread ( and couldn't get the method suggested to accept the user type. This thread tiltle is more to the point.

Win XP Excel 2002 (VBA/VB 6)

though I do try this at home (Win98 ditto)

Word Document is open, macro in normal.dot, Excel in control. macro will be manipulating the text of the Word doc. If working I might try passing values though I suspect this is not possible.

All suggestions welcome





there is a tide in the affairs of man that you Canute ignore.................
 
Try this syntax:
yourWordApp.Run "Normal.NameOfModule.NameOfMacro"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK I am a little slow
The "yourWordApp" is an object right?
It has to be declared somewhere
I run the Word app/doc by:
Code:
 Shell ("winword.exe """ & varholdingname & """")

I am still missing how to define "your" :
Code:
 Application.Run ("Normal.NewMacros.dater")
application needs a definition and "help" hasn't revealed anything yet. I am struggling.

there is a tide in the affairs of man that you Canute ignore.................
 
You don't have any Word.Application object instantiated ?????

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
this is as far as I got, comments lines indicate attempts to change things
Code:
Sub trial(): 'Dim mywordapp As Object
mywordapp = CreateObject("Word.Application")
'Application.ActivateMicrosoftApp xlMicrosoftWord
mywordapp.Run "Normal.NewMacros.dater"
End Sub
the .Run line needs an object
Word already loaded with target doc
I suspect I have to reference the doc by name but help doesn't help.
Tek-Tips only offers one FAQ inclucing the words "Word" and "instantiate" which may have helped - bot sure.

there is a tide in the affairs of man that you Canute ignore.................
 
Thanx 4 sticking with me.

there is a tide in the affairs of man that you Canute ignore.................
 
found this but not the word instantiate in VBA help nor MSDL nor Cambridge dictionay. Websters - yes. US dielect?

this code does work
Code:
Sub trial()
      Dim WD As Object
      Set WD = CreateObject("Word.Application")
      WD.Documents.Open "C:\Omega_Dell\PURCHASE ORDERS\WordDoc.Doc"
      ' Note that the project name and module name are required to
      ' path the macro correctly.
      WD.Run "Normal.NewMacros.dater"
End Sub
It loads Word and opens the doc but shuts it all down again. The text in quotes seems to be case sensitive.
So now I have to figure how to retain the doc and carry on running other macros after manula tinkering. That should be easy.

there is a tide in the affairs of man that you Canute ignore.................
 
That is about as far as I got. Opening a doc with "shell" really screws-up because running the macros from Excel opens a second instance. And leaves Word hanging in a curious state - probably waiting for something. So my only option is to run the macro and re-open later for manual tinkering.

there is a tide in the affairs of man that you Canute ignore.................
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top