How to write a macro to import an event procedure to ThisWorbook?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have an event procedure (Workbook_BeforeSave) which I tried to write a
macro to import into ThisWorkbook. The reason for doing this is that I try to
format this procedure into 1200 Excel files and it is impossible I do it
manually.

I tried to use the following code to accomplish this. But it didn't work.

With ThisWorkbooks.VBProject.VBComponents
.Import impfile
End With

It was imported but didn't go to ThisWorkbook. It added a new module instead.

Anyone can help me to resolve this problem? This is my 1st post in this forum.

Thanks a lot!

utdcr,
 
ThisWorkbook is a class module, and as such you cannot import the file
because import creates the modules, and ThisWorkbook already exists. .

You could try AddFromFile. Save the code in a text file and use this code

ActiveWorkbook.VBProject.VBComponents("ThisWorkbook") _
.CodeModule.AddFromFile "C:\myTest\Text1.txt"

where the text file holds the vcomplete event code.

The problem is that you could add an event that is already present.


--

HTH


RP
(remove nothere from the email address if mailing direct)
 

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

Back
Top