Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to write a macro to import an event procedure to ThisWorbook?

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,


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to write a macro to import an event procedure to ThisWorbook?

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("ThisWorkboo k") _
.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)


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




  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default How to write a macro to import an event procedure to ThisWorbook?

hi,
check this site out.
http://cpearson.com/excel/vbe.htm
lot of good info on writting code with code.

-----Original Message-----
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,


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to write a macro to import an event procedure to ThisWorbo

That works! Thanks Bob!

I love this forum!

utdcr.

"Bob Phillips" wrote:

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("ThisWorkboo k") _
.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)


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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using A Macro To Add Event Procedure To A CommandButton Donna[_7_] Excel Programming 1 February 8th 05 11:59 PM
Event Procedure Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:29 PM
Event Procedure again Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:28 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM


All times are GMT +1. The time now is 11:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"