Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
michaelberrier
 
Posts: n/a
Default Executing macro in one book from another.

I'm attempting to adapt Chip Pearson's code for deleting all code in a
workbook to run from a different workbook.

I've tried adding "With Workbooks("Book1") before the code in Book2,
but that still deletes all the code in Book2. Here is the code that I
started with:

Sub DeleteAllVBA()

Dim VBComp As VBIDE.VBComponent
Dim VBComps As VBIDE.VBComponents

Set VBComps = ActiveWorkbook.VBProject.VBComponents

For Each VBComp In VBComps
Select Case VBComp.Type
Case vbext_ct_StdModule, vbext_ct_MSForm, _
vbext_ct_ClassModule
VBComps.Remove VBComp
Case Else
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
End Select
Next VBComp

End Sub
Thanks for the help.

  #2   Report Post  
Posted to microsoft.public.excel.misc
Norman Jones
 
Posts: n/a
Default Executing macro in one book from another.

Hi Michael,

I'm attempting to adapt Chip Pearson's code for deleting all code in a
workbook to run from a different workbook.

I've tried adding "With Workbooks("Book1") before the code in Book2,
but that still deletes all the code in Book2. Here is the code that I
started with:


Try replacing

Set VBComps = ActiveWorkbook.VBProject.VBComponents


with

Set VBComps = Workbooks("Book2"). _
VBProject.VBComponents

or

Set VBComps = Workbooks("Book2.xls"). _
VBProject.VBComponents

if the workbook has been saved


---
Regards,
Norman


  #3   Report Post  
Posted to microsoft.public.excel.misc
michaelberrier
 
Posts: n/a
Default Executing macro in one book from another.

Norman,
That works great. Now, I'd like to make the book that code will be
delete from dynamic based on the value of a combobox in a userform.
I've tried some subsitituions in the code but can't make it work. Any
ideas?

thanks again.
Norman Jones wrote:
Hi Michael,

I'm attempting to adapt Chip Pearson's code for deleting all code in a
workbook to run from a different workbook.

I've tried adding "With Workbooks("Book1") before the code in Book2,
but that still deletes all the code in Book2. Here is the code that I
started with:


Try replacing

Set VBComps = ActiveWorkbook.VBProject.VBComponents


with

Set VBComps = Workbooks("Book2"). _
VBProject.VBComponents

or

Set VBComps = Workbooks("Book2.xls"). _
VBProject.VBComponents

if the workbook has been saved


---
Regards,
Norman


  #4   Report Post  
Posted to microsoft.public.excel.misc
Norman Jones
 
Posts: n/a
Default Executing macro in one book from another.

Hi Michael,

That works great. Now, I'd like to make the book that code will be
delete from dynamic based on the value of a combobox in a userform.
I've tried some subsitituions in the code but can't make it work. Any
ideas?


Try:

Dim VBComp As VBIDE.VBComponent
Dim VBComps As VBIDE.VBComponents
Dim WB as workbook

Set WB= Workbooks( UserForm1.ComboBox1.Value & ".xls")

Set VBComps = WB.VBProject.VBComponents


---
Regards,
Norman


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
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Highlight Range - wrong macro, please edit. Danny Excel Worksheet Functions 8 October 19th 05 11:11 PM
Need Macro for List of Book Titles Edye Excel Worksheet Functions 11 August 11th 05 11:00 AM
Executing macro for all worksheet from a different worksheet Biti New Users to Excel 3 December 8th 04 10:05 AM


All times are GMT +1. The time now is 11:59 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"