Don Trembly
Don Trembly

Reputation: 17

What is the command in Excel VBA to delete a specific macro?

I have an Excel Macro Template. I run a macro on it and it saves the new spreadsheet as an xlsx instead.

I'm just wondering if there's a simple command for VBA that just deletes a macro by name.

I've researched this a lot, and there are basically two answers which don't really fit.

The first is to not have macros in the workbook I'm saving and to just run macros from one workbook to another. (I don't want to do this for a few reasons, but simplicity is the main reason.)

The second is a VBA script that strips ALL VBA and connections from the workbook. (I don't need it to do that much, and I'd rather just delete the one macro I have.)

So, what I'm looking for is just something like this:

Delete.Macro("Import") 'This command deletes the macro in this workbook named "Import".

Upvotes: 0

Views: 5162

Answers (2)

user3598756
user3598756

Reputation: 29421

try

Sub main()

Application.DisplayAlerts = False   
Workbooks("PutWorkBookName").SaveAs FileFormat:=xlOpenXMLWorkbook    
Application.DisplayAlerts = True

End Sub

Upvotes: 1

CWilson
CWilson

Reputation: 435

Fun thought, use VBA to remove VBA... but seems more work than necessary.

What about activeworkbook.saveas "filename.xlsx", xlExcel12?

As I am sure you are aware, an .xlsx doesn't have any code, so if you set warnings to false, etc., it will just save the file and delete the code.

Now, if I misread, and you want to delete only some of your code, leave the rest, and save as xlsx... you are out of luck.

Upvotes: 0

Related Questions