Empty a Module within Excel 2016 …

Russ1701

New Member
Joined
Apr 30, 2003
Messages
17
Using VBA in Excel 2016, how can I empty a standard module with appropriate VBA code without deleting it? Although I am able to delete a module, create a module, rename a module … I simply need to open an existing module and remove all code from within it so that it is completely empty. Thank you.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
You can use the DeleteLines method to delete the code from a module.

For example, this will delete all the code from Module1.
Code:
Sub DeleteAllCodeFromModule()
Dim IDE As Object
Dim mdl As Object

    Set IDE = ActiveWorkbook.VBProject

    Set mdl = IDE.VBComponents("Module1").CodeModule

    mdl.DeleteLines StartLine:=1, Count:=mdl.CountOfLines

End Sub


PS Why do you want to do this?
 
Upvote 0
… I simply need to open an existing module and remove all code from within it so that it is completely empty.
Why not simply click anywhere in the module, press CTRL+A followed by the Delete key? Seems easy and fast enough to do to me.
 
Last edited:
Upvote 0
Yes, CTRL+A & Delete does indeed work, but I am automating the process programmatically, without human intervention. I tried SendKeys but does not always work correctly, at its best (not to mention that it is best avoided during coding). Thanks.
 
Upvote 0

Forum statistics

Threads
1,216,140
Messages
6,129,105
Members
449,486
Latest member
malcolmlyle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top