ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Delete Another WorkBook Macros (https://www.excelbanter.com/excel-programming/335357-how-delete-another-workbook-macros.html)

ddiicc

How to Delete Another WorkBook Macros
 
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??


KL

How to Delete Another WorkBook Macros
 
Hi,

you can try the folloowing code placing it in any place of any module of
Workbook A:

Sub Remove_Modules()
With Workbooks("HSA template 2.xls").VBProject
.VBComponents.Remove .VBComponents("SortData")
.VBComponents.Remove .VBComponents("CrunchData")
End With
End Sub

Regards,
KL


"ddiicc" wrote in message
...
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??




KL

How to Delete Another WorkBook Macros
 
Hi again,

The code below does for me what you describe. You may need to go to the VBA
Editor's menu ToolsReferences and set a reference to 'Microsoft Visual
Basic for Application Extensibility #.#' library.

Regards,
KL

Sub Remove_Modules()
Dim arrMod As Variant
Dim prOld As VBIDE.VBProject
Dim mdNew As VBIDE.CodeModule

Set mdNew = Workbooks("HSA template 1.xls").VBProject. _
VBComponents("AllDataYieldCrunch").CodeModule
Set prOld = Workbooks("HSA template 2.xls").VBProject
arrMod = Array("SortData", "CrunchData")

mdNew.InsertLines mdNew.CountOfLines + 1, Chr(13)
For i = LBound(arrMod) To UBound(arrMod)
With prOld.VBComponents(arrMod(i)).CodeModule
COL = .CountOfLines
For j = 1 To COL
mdNew.InsertLines mdNew.CountOfLines + 1, .Lines(j, 1)
Next j
mdNew.InsertLines mdNew.CountOfLines + 1, Chr(13)
prOld.VBComponents.Remove prOld.VBComponents(arrMod(i))
End With
Next i
End Sub



Norman Jones

How to Delete Another WorkBook Macros
 
Hi Ddiicc,

Assuming that you do mean to delete discrete modules and not individual subs
housed in a module, see response(s) in your original thread.


---
Regards,
Norman



"ddiicc" wrote in message
...
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??





All times are GMT +1. The time now is 04:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com