Home |
Search |
Today's Posts |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try
Sub CopyThisWorkbook() Dim ThisVBComp As VBIDE.VBComponent Dim ThatVBComp As VBIDE.VBComponent Dim S As String Set ThisVBComp = ThisWorkbook.VBProject.VBComponents("ThisWorkbook" ) Set ThatVBComp = Workbooks("Book3").VBProject.VBComponents("ThisWor kbook") With ThisVBComp.CodeModule S = .Lines(1, .CountOfLines) End With With ThatVBComp.CodeModule .DeleteLines 1, .CountOfLines .AddFromString S End With End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel, 10 Years Pearson Software Consulting www.cpearson.com (email on the web site) "Otto Moehrbach" wrote in message ... Chip I had another question in this thread regarding altering the code you gave me for manipulating code in a sheet module, to make it work with a Workbook module. You may have overlooked that query and I would appreciate your help with this. Here is the query: Chip I'm learning things here that I've never been into before. And I thank you for that. The code you gave me is for a sheet module and I can put it to good use. How would I modify that code to work with the Workbook module? Thanks for your time. Otto "Chip Pearson" wrote in message ... I noticed that setting the Extensibility reference does not stay put when I shut down Excel and reopen it. Is that normal behavior? No, that is not normal behavior. The reference will come and go as that workbook is opened or closed, but that workbook should always have that reference set. References are part of the workbook, so every workbook that needs to use a reference must have it checked in the VBProject. -- Cordially, Chip Pearson Microsoft MVP - Excel, 10 Years Pearson Software Consulting www.cpearson.com (email on the web site) "Otto Moehrbach" wrote in message ... Chip I noticed that setting the Extensibility reference does not stay put when I shut down Excel and reopen it. Is that normal behavior? Thanks for your time. Otto "Chip Pearson" wrote in message ... Try something like the following. You'll need a reference to the Extensibility library. Sub CopySheetModule() Dim ThisVBP As VBIDE.VBProject Dim ThatVBP As VBIDE.VBProject Dim ThisVBComp As VBIDE.VBComponent Dim ThatVBComp As VBIDE.VBComponent Dim S As String Set ThisVBP = ThisWorkbook.VBProject Set ThatVBP = Workbooks("Book2").VBProject '<<< CHANGE Set ThisVBComp = ThisVBP.VBComponents("Sheet1") '<<< CHANGE Set ThatVBComp = ThatVBP.VBComponents("Sheet1") '<<< CHANGE With ThisVBComp.CodeModule S = .Lines(1, .CountOfLines) End With With ThatVBComp.CodeModule .DeleteLines 1, .CountOfLines .AddFromString S End With End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel, 10 Years Pearson Software Consulting www.cpearson.com (email on the web site) "Otto Moehrbach" wrote in message ... Excel XP and Win XP I have used code furnished by Chip Pearson to copy a module from one file to another. I believe, maybe I'm wrong, that this code deals with regular modules only. My question now is: Can this be done with a sheet or workbook module? And how? Thanks for your time. Otto |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Run worksheet module code from workbook module? | Excel Programming | |||
VB Code Location; sheet, workbook, module | Excel Programming | |||
Sheet Code Module: copying code to | Excel Programming | |||
Write VBA code into a sheet module using VBA | Excel Programming | |||
Adding Code Module to Workbook | Excel Programming |