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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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