Programmatically Writing/Copying Macros to a Document

G

George Lee

How do you write macro code to existing document?

For example, from within my host application the user will be able to open a
document. I would like to add a macro to that document only. I will not have
control over the document ahead of time, nor the template they are using.

So how would you programmatically copy or write macros to a document?
 
J

Jonathan West

George Lee said:
How do you write macro code to existing document?

For example, from within my host application the user will be able to open
a
document. I would like to add a macro to that document only. I will not
have
control over the document ahead of time, nor the template they are using.

So how would you programmatically copy or write macros to a document?

You can use the OrganizerCopy method to copy a module into the document.

But if the user has High security set in Word, the macro won't run anyway.
And you can't change the security level through code.

What exactly are you trying to achieve?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
G

George Lee

I want to dynamically add a macro to an active document. The Import method of
VBE interface works for the most part but I can't see where it adds macros to
the currently attached template. I'd like to add an AutoExit dynamically when
a certain file is opened and remove the macro when when the file is closed.
 
J

Jonathan West

George Lee said:
I want to dynamically add a macro to an active document. The Import method
of
VBE interface works for the most part but I can't see where it adds macros
to
the currently attached template. I'd like to add an AutoExit dynamically
when
a certain file is opened and remove the macro when when the file is
closed.

An AutoExit macro will only fire then the document is unloaded as an add-in.
It won't run at all when the document is opened or closed.

What is this AutoExit macro supposed to be doing?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
G

George Lee

I want to intercept the some files being closed. I can intercept the "Close"
menu command, the "Exit" command, and the document close button. I can't make
that interception if the user closes the document by clicking the
application's window X button, which is actually the most likely way they'll
close the document. I'd rather not have a global interception in everyone's
template. That gets me to adding a routine to individual document's template.
Is that incorrect thinking?
 
Top