View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
ddiicc ddiicc is offline
external usenet poster
 
Posts: 42
Default How to Delete Another WorkBook Macros using Macros.. Possible?

Hi Norman,
I have try and try but still I receive some errors.

I will stated my examples clearly, so you could help me or give me the words
to fill in the blanks.

"Workbook A" name is "HSA template 1"
"Workbook B" name is "HSA template 2"

Workbook A contains a module name "AllDataYieldCrunch"
Workbook B conains a 2 module name, 1st is "SortData", 2nd is "CrunchData"

So in my workbook A, I want to add the code, macro or scripts, inside my
module "AllDataYieldCrunch" together. Then it will also delete the 2 modules
in
workbook B.

Workbook A module stated below :-

Sub ########()

####$##^^%&^
#$#%^$^&*(&&
}#%^%$%&*^(&

ActiveWorkbook.SaveAs Filename:="E:\HSA Template 2", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, CreateBackup:=False


End Sub.

So where should I place the script?? before the end sub??


"Norman Jones" wrote:

Hi Ddiicc,

On the link page I gave you, Chip Pearson gives a DeleteAllVBA procedure
which 'does what it says on the label'.

Customising for your specific workbook, try:

Sub DeleteAllVBA()

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

Set WB = Workbooks("HSA LGC01.xls")

Set VBComps = WB.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

'=====================================
Before using this code, thank Chip and carefully read the warning he
provided for the procedu
The procedure below will delete all the VBA code in a project. You should
use this procedure with care, as it will permanently delete the code.
Standard modules, user forms, and class modules will be removed, and code
within the ThisWorkbook module and the sheet modules will be deleted. You
may want to export the VBA code, using the procedure above, before deleting
the VBA code.
'<<=====================================

---
Regards,
Norman



"ddiicc" wrote in message
...
Hi Norman,
Thanks for responding, I am rather a beginner in macro writing,
So I would like to ask on how to add in the code that you given.
Eg..My ending of the macros is stated below.

ActiveWorkbook.SaveAs Filename:="E:\Jong\Python A HSA\HSA Yield For All
Lines 2005\C LGC\All HSA LGC Stations Yield\G Jul 2005 LGC Yield\HSA LGC01
All Model 1st Pass Yield Jul 2005.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub


So how do I add in the script you have given, I have about 11 modules to
delete
after the workbook is saved as stated on the above...

Regards ddiicc

"Norman Jones" wrote:

Hi Ddiicc,

Try:

Sub DeleteModule()
Dim VBComp As VBComponent
Set VBComp = Workbooks("Book2.xls").VBProject. _

VBComponents("NewModule")
Workbooks("Book2.xls").VBProject.VBComponents.Remo ve VBComp
End Sub


---
Regards,
Norman



"ddiicc" wrote in message
...
Hi Norman,

What If I want to delete a module in another workbook 2 using the
module
in
workbook 1... so how should go about writing this in workbook module???



"Norman Jones" wrote:

Hi Ddiicc,

See Chip Pearson VBE programming page at:

http://www.cpearson.com/excel/vbe.htm

See particularly the section entitled: Deleting A Procedure From A
Module


---
Regards,
Norman



"ddiicc" wrote in message
...
Hi to the experts in excel programming.

What is the commands or script for deleting a macro automatically
using
another workbook macro.