Hi,

I want to do the following:

1. open a new document based on a template
2. in this document, insert another word document (which I select
using a listbox)
3. after the word-document is inserted, run the code that is inside
the inserted word document

Step 1 and 2 are not a problem. However, I use

Selection.InsertFile FileName:=myName, Range:="" to insert the new
word document.

In this document I want to use the code that is in this document to
run, the moment the insertion is done. I used AutoOpen, AutoNew,
Document Open in the document to insert, but nothing works. I think
this is because the document is inserted, not opened!

Is there a solution?

Thanks, Mike

Re: Run macro after InsertFile by Jonathan

Jonathan
Fri Aug 03 08:32:55 CDT 2007


"Mike" <Mike_Gator14@yahoo.com> wrote in message
news:1186135715.479335.163660@q75g2000hsh.googlegroups.com...
> Hi,
>
> I want to do the following:
>
> 1. open a new document based on a template
> 2. in this document, insert another word document (which I select
> using a listbox)
> 3. after the word-document is inserted, run the code that is inside
> the inserted word document
>
> Step 1 and 2 are not a problem. However, I use
>
> Selection.InsertFile FileName:=myName, Range:="" to insert the new
> word document.
>
> In this document I want to use the code that is in this document to
> run, the moment the insertion is done. I used AutoOpen, AutoNew,
> Document Open in the document to insert, but nothing works. I think
> this is because the document is inserted, not opened!

You are correct.

>
> Is there a solution?
>
>

In order to make the macro available for use, after inserting the file into
the current document, temporarily load the file as an add-in, using the Add
method of the AddIns collection. You can then use the Application.Run method
to run any macro in that document. Afterwards, unload the add-in and use the
Remove method to remove it from the add-ins list in the Tools, Templates and
Addins dialog.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup