Create a macro to delete modules, userforms,
Solved
yao.chris
Posted messages
95
Status
Member
-
yao.chris Posted messages 95 Status Member -
yao.chris Posted messages 95 Status Member -
Hello,
do you know how to create a macro that allows you to delete modules, userforms, ThisWorkbook code, and sheet code?
I have tried the codes I found online but none of them work.
Thank you for your help.
yao
do you know how to create a macro that allows you to delete modules, userforms, ThisWorkbook code, and sheet code?
I have tried the codes I found online but none of them work.
Thank you for your help.
yao
5 answers
Hello Forum
Have you added the reference
"Microsoft Visual Basic For Application Extensibility x.x"?
Mytå
--
Thank you for following up on your question, we are not robots...
“If debugging is the art of removing bugs, then programming must be the art of creating them.”
Have you added the reference
"Microsoft Visual Basic For Application Extensibility x.x"?
Mytå
--
Thank you for following up on your question, we are not robots...
“If debugging is the art of removing bugs, then programming must be the art of creating them.”
Good evening Myta,
Thank you for your response.
Yes, I did it but with no results.
Is there a way to create a macro without adding this reference?
Thank you for your help.
yao
Thank you for your response.
Yes, I did it but with no results.
Is there a way to create a macro without adding this reference?
Thank you for your help.
yao
Hello Forum
To delete code modules.
In the macro security section, there is a tab called "Trusted Publishers".
In this tab, you need to check "Trust access to the VBA project object model".
Mytå
--
Thank you for following up on your question, we are not robots...
“If debugging is the art of removing bugs, then programming must be the art of introducing them.”
To delete code modules.
Sub DeleteModule() 'Macro to delete code modules from the workbook Dim i As Integer For i = ThisWorkbook.VBProject.VBComponents.Count To 1 Step -1 If ThisWorkbook.VBProject.VBComponents.Item(i).Type = 1 Then ThisWorkbook.VBProject.VBComponents.Remove ThisWorkbook.VBProject.VBComponents.Item(i) End If Next i End Sub
In the macro security section, there is a tab called "Trusted Publishers".
In this tab, you need to check "Trust access to the VBA project object model".
Mytå
--
Thank you for following up on your question, we are not robots...
“If debugging is the art of removing bugs, then programming must be the art of introducing them.”
Good evening Mytå,
I just applied your macro.
Everything works great except for Type 100; I have a runtime error on Focus.
The most important thing for me was to remove the Userforms and modules.
Types 1 and 3 work perfectly.
Thank you very much for your help.
Good night.
yao
I just applied your macro.
Everything works great except for Type 100; I have a runtime error on Focus.
The most important thing for me was to remove the Userforms and modules.
Types 1 and 3 work perfectly.
Thank you very much for your help.
Good night.
yao
Re the Forum
To delete all VBA modules from the file.
Mytå
To delete all VBA modules from the file.
Sub DeleteAllCodeInModule() Dim VBCodeMod As Object Dim I As Long With ThisWorkbook.VBProject For I = 1 To .VBComponents.Count Set VBCodeMod = .VBComponents(I).CodeModule VBCodeMod.DeleteLines 1, VBCodeMod.CountOfLines Next I End With End Sub
Mytå