
copy module to another module
Maria,
You could manipulate the workbook's VBA project with code. To do this you
need to reference the VBA Extensibility library (in the VBA Editor for your
workbook, go to Tools > References and check "Visual Basic Extensibility
Library").
Then you could use code like this to append the code from one module to
another:
Dim oBook As Workbook
Dim oModule1 As VBComponent, oModule2 As VBComponent
Set oBook = Workbooks.Open("c:\book1.xls")
Set oModule1 = oBook.VBProject.VBComponents("Module1")
Set oModule2 = oBook.VBProject.VBComponents("Sheet1")
'Get the code in Module1
Dim n As Long, sCode As String
n = oModule1.CodeModule.CountOfLines
sCode = oModule1.CodeModule.Lines(1, n)
'Append the code from Module1 to the code module for Sheet1
n = oModule2.CodeModule.CountOfLines
'oModule2.CodeModule.DeleteLines 1, n 'Use if you want to clear the
code in Sheet1 first
oModule2.CodeModule.InsertLines n + 1, sCode
Hope this helps,
Lori Turner
Microsoft Developer Support
--------------------
Quote:
>>Subject: copy module to another module
>>Date: Fri, 17 Aug 2001 09:56:57 -0500
>>Lines: 6
>>Organization: UW Colleges
>>X-Priority: 3
>>X-MSMail-Priority: Normal
>>X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
>>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
>>Newsgroups: microsoft.public.office.developer.vba
>>NNTP-Posting-Host: adm632464.uwc.edu 143.235.2.195
>>Path: cppssbbsa01.microsoft.com!tkmsftngp01!tkmsftngp07
>>Xref: cppssbbsa01.microsoft.com microsoft.public.office.developer.vba:6711
>>X-Tomcat-NG: microsoft.public.office.developer.vba
>>Does anyone know how to copy a module (Module 2) to the coding behind a
>>worksheet (Sheet3 (Central Office))?