Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Copy module with code - amendment

I have this code which copies a specific routine into the
Thisworkbook module of a specific workbook.

There is code before this routine which I wish not to
copy, but I have now added code after this routine.

I could use the copy statements for each of the extra
routines, but I wondered if there was another way?

Public Sub CopySheetChangeEventFromAnyBook _
(ByVal NewWorkbookName As String)

'This will only execute if the calling Workbook is unprotected.

Dim SourceCodeModule As VBIDE.CodeModule
Dim DestCodeModule As VBIDE.CodeModule
Dim wb As Workbook, StartCopyLine As Long
Dim NumberOfLines As Long

Set SourceCodeModule = _
ThisWorkbook.VBProject. _
VBComponents("ThisWorkbook").CodeModule

Set DestCodeModule = _
Workbooks(NewWorkbookName & ".xls").VBProject. _
VBComponents("ThisWorkbook").CodeModule

StartCopyLine = SourceCodeModule.ProcStartLine _
("Workbook_SheetChange", vbext_pk_Proc)
NumberOfLines = SourceCodeModule.ProcCountLines _
("Workbook_SheetChange", vbext_pk_Proc)

DestCodeModule.InsertLines DestCodeModule.CountOfLines + 1, _
SourceCodeModule.Lines(StartCopyLine, NumberOfLines)

End Sub

Could I therefore tell it to start with the "Workbook_SheetChange"
routine, and then copy all following routines?

Regards.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.786 / Virus Database: 532 - Release Date: 29/10/2004


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Copy module with code - amendment

Try getting the number of lines to copy like this:

NumberOfLines = SourceCodeModule.CountOfLines - StartCopyLine

--
Jim Rech
Excel MVP


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Copy module with code - amendment

Many thanks.

Regards.

"Jim Rech" wrote in message
...
Try getting the number of lines to copy like this:

NumberOfLines = SourceCodeModule.CountOfLines - StartCopyLine

--
Jim Rech
Excel MVP




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.786 / Virus Database: 532 - Release Date: 29/10/2004


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
Unprotect Code Module in Code Damien Excel Discussion (Misc queries) 2 April 18th 06 03:10 PM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM
copying vba code to a standard code module 1vagrowr Excel Discussion (Misc queries) 2 November 23rd 05 04:00 PM
Is it possible to copy a code module using VBA? quartz Excel Programming 2 April 15th 04 09:49 PM
Merged Cells Autofit - code amendment roy Excel Programming 7 November 4th 03 12:19 PM


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

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"