GetObject to Open Word containing Macros

K

Kris_Wright_77

From examples of retrieving information held with a Form in Microsoft Word, I
have a macro that opens up a collection of forms to update a register held
within Excel

It all works provided that either the word forms do not contain macros or I
sit there and click Disable or Enable Macros for every form.

Is there any way to tell Word to Get the forms without activating the Macros?
- Or always activating them as it makes no difference to the information
being retrieved and wont be run by just opening

Set Wd = GetObject(Range("RFI_Location").Value & ImportForm)
where RFI_Lacation is the Filepath & ImportForm is the Filename (from a
macro that seaches the Filepath for the forms)

Is there another method that I should use, if GetObject isnt the right one?


Thanks very much for any help that anyone can give.

Kris
 
P

Peter T

When you 'automate' Word and open a document with macros you should not get
the macro security warning. Try something like this

Sub test()
Dim sDoc As String
Dim objWd As Object
Dim objDoc As Object
sDoc = "C:\< path >\testDoc with macro.doc"

On Error Resume Next
Set objWd = GetObject(, "word.application")
On Error Resume Next
If objWd Is Nothing Then
Set objWd = CreateObject("word.application")
End If

objWd.Visible = True
Set objDoc = objWd.documents.Open(sDoc)
AppActivate objWd.Caption ' lazy way to make it active

objWd.Run ("myMacro") ' a macro in the word document
End Sub

GetObject will attempt to find a running instance of Word (might even be
your Outlook email editor). If it fails use CreateObject to start your own.
You might also want an extra flag so you'll know to quit the new instance
when done, not included above.

Regards,
Peter T
 
K

Kris_Wright_77

Thanks very much

Using CreateObject stopped the macro security warning popping up
 

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