ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   GetObject to Open Word containing Macros (https://www.excelbanter.com/excel-programming/430223-getobject-open-word-containing-macros.html)

Kris_Wright_77

GetObject to Open Word containing Macros
 

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

Peter T

GetObject to Open Word containing Macros
 

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

"Kris_Wright_77" wrote in message
...
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




Kris_Wright_77

GetObject to Open Word containing Macros
 

Thanks very much

Using CreateObject stopped the macro security warning popping up

"Peter T" wrote:

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

"Kris_Wright_77" wrote in message
...
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






All times are GMT +1. The time now is 12:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com