Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default CodeModule utilization problem

Dear experts,
I have a VBA code in workbook "A" that writes VBA code in workbook "B".
The code looks like:

With ActiveWorkbook.VBProject.VBComponents("Sheet4").Co deModule
StartLine = .CreateEventProc("Change", "Worksheet") + 1
.InsertLines StartLine, _
Etc.

It works on putting the code in Sheet4, but as Sheet4 is a created worksheet
by another macro, it is not always the sheet where I want the code!
Is there a way that I can tell VBA to put the code in the sheet called
"Data" instead than on Sheet4?

Thank you very much for your help.
Best regards
Valeria

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default CodeModule utilization problem

It's easy to get the sheet's code module from its worksheet name:

Worksheets("Data").CodeName

--
Jim
"Valeria" wrote in message
...
| Dear experts,
| I have a VBA code in workbook "A" that writes VBA code in workbook "B".
| The code looks like:
|
| With ActiveWorkbook.VBProject.VBComponents("Sheet4").Co deModule
| StartLine = .CreateEventProc("Change", "Worksheet") + 1
| .InsertLines StartLine, _
| Etc.
|
| It works on putting the code in Sheet4, but as Sheet4 is a created
worksheet
| by another macro, it is not always the sheet where I want the code!
| Is there a way that I can tell VBA to put the code in the sheet called
| "Data" instead than on Sheet4?
|
| Thank you very much for your help.
| Best regards
| Valeria
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default CodeModule utilization problem

Hi,
I have tried this:

With ActiveWorkbook.Worksheets("Data").CodeName
StartLine = .CreateEventProc("Change", "Worksheet") + 1
etc.

But I get the error "object required"...
Thanks for helping me!
Kind regards
--
Valeria


"Jim Rech" wrote:

It's easy to get the sheet's code module from its worksheet name:

Worksheets("Data").CodeName

--
Jim
"Valeria" wrote in message
...
| Dear experts,
| I have a VBA code in workbook "A" that writes VBA code in workbook "B".
| The code looks like:
|
| With ActiveWorkbook.VBProject.VBComponents("Sheet4").Co deModule
| StartLine = .CreateEventProc("Change", "Worksheet") + 1
| .InsertLines StartLine, _
| Etc.
|
| It works on putting the code in Sheet4, but as Sheet4 is a created
worksheet
| by another macro, it is not always the sheet where I want the code!
| Is there a way that I can tell VBA to put the code in the sheet called
| "Data" instead than on Sheet4?
|
| Thank you very much for your help.
| Best regards
| Valeria
|



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default CodeModule utilization problem

You need something like

Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents( _
ActiveWorkbook.Worksheets("Sheet3").CodeName).Code Module
StartLine = .CreateEventProc("Change", "Worksheet")
End With



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Valeria" wrote in message
...
Hi,
I have tried this:

With ActiveWorkbook.Worksheets("Data").CodeName
StartLine = .CreateEventProc("Change", "Worksheet") + 1
etc.

But I get the error "object required"...
Thanks for helping me!
Kind regards
--
Valeria


"Jim Rech" wrote:

It's easy to get the sheet's code module from its worksheet
name:

Worksheets("Data").CodeName

--
Jim
"Valeria" wrote in message
...
| Dear experts,
| I have a VBA code in workbook "A" that writes VBA code in
workbook "B".
| The code looks like:
|
| With
ActiveWorkbook.VBProject.VBComponents("Sheet4").Co deModule
| StartLine = .CreateEventProc("Change", "Worksheet") + 1
| .InsertLines StartLine, _
| Etc.
|
| It works on putting the code in Sheet4, but as Sheet4 is a
created
worksheet
| by another macro, it is not always the sheet where I want
the code!
| Is there a way that I can tell VBA to put the code in the
sheet called
| "Data" instead than on Sheet4?
|
| Thank you very much for your help.
| Best regards
| Valeria
|





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default CodeModule utilization problem

sName = ActiveWorkbook.Worksheets("Data").CodeName
With ActiveWorkbook.VBProject.VBComponents(sName).CodeM odule
StartLine = .CreateEventProc("Change", "Worksheet") + 1
.InsertLines StartLine, _


--
Regards,
Tom Ogilvy

"Valeria" wrote in message
...
Hi,
I have tried this:

With ActiveWorkbook.Worksheets("Data").CodeName
StartLine = .CreateEventProc("Change", "Worksheet") + 1
etc.

But I get the error "object required"...
Thanks for helping me!
Kind regards
--
Valeria


"Jim Rech" wrote:

It's easy to get the sheet's code module from its worksheet name:

Worksheets("Data").CodeName

--
Jim
"Valeria" wrote in message
...
| Dear experts,
| I have a VBA code in workbook "A" that writes VBA code in workbook

"B".
| The code looks like:
|
| With ActiveWorkbook.VBProject.VBComponents("Sheet4").Co deModule
| StartLine = .CreateEventProc("Change", "Worksheet") + 1
| .InsertLines StartLine, _
| Etc.
|
| It works on putting the code in Sheet4, but as Sheet4 is a created
worksheet
| by another macro, it is not always the sheet where I want the code!
| Is there a way that I can tell VBA to put the code in the sheet called
| "Data" instead than on Sheet4?
|
| Thank you very much for your help.
| Best regards
| Valeria
|







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default CodeModule utilization problem

This works wonderfully, thank you very much!
Best regards
Valeria
--
Valeria


"Tom Ogilvy" wrote:

sName = ActiveWorkbook.Worksheets("Data").CodeName
With ActiveWorkbook.VBProject.VBComponents(sName).CodeM odule
StartLine = .CreateEventProc("Change", "Worksheet") + 1
.InsertLines StartLine, _


--
Regards,
Tom Ogilvy

"Valeria" wrote in message
...
Hi,
I have tried this:

With ActiveWorkbook.Worksheets("Data").CodeName
StartLine = .CreateEventProc("Change", "Worksheet") + 1
etc.

But I get the error "object required"...
Thanks for helping me!
Kind regards
--
Valeria


"Jim Rech" wrote:

It's easy to get the sheet's code module from its worksheet name:

Worksheets("Data").CodeName

--
Jim
"Valeria" wrote in message
...
| Dear experts,
| I have a VBA code in workbook "A" that writes VBA code in workbook

"B".
| The code looks like:
|
| With ActiveWorkbook.VBProject.VBComponents("Sheet4").Co deModule
| StartLine = .CreateEventProc("Change", "Worksheet") + 1
| .InsertLines StartLine, _
| Etc.
|
| It works on putting the code in Sheet4, but as Sheet4 is a created
worksheet
| by another macro, it is not always the sheet where I want the code!
| Is there a way that I can tell VBA to put the code in the sheet called
| "Data" instead than on Sheet4?
|
| Thank you very much for your help.
| Best regards
| Valeria
|






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
Low CPU Utilization Eric Excel Discussion (Misc queries) 4 August 7th 07 03:24 PM
Excel crashes when using CreateEventProc towards CodeModule Bertil Emmertz Excel Programming 2 December 5th 04 10:35 AM
get linenumber when string found in VBE codemodule RB Smissaert Excel Programming 11 October 10th 04 09:56 AM
insert lines into CODEMODULE gives error Marek Excel Programming 0 September 23rd 04 05:18 PM
Optimize RAM Utilization Ken Wright Excel Programming 0 June 2nd 04 09:52 PM


All times are GMT +1. The time now is 07:05 PM.

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

About Us

"It's about Microsoft Excel"