Run macro after InsertFile

M

Mike

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
 
J

Jonathan West

Mike said:
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.
 

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