Remove VBA code used in template

cm3pyro

New Member
Joined
Jul 12, 2010
Messages
5
I am working on a template that when the information is entered and the user clicks the SaveAs button the SaveAs dialog window directs them to the correct directory and inserts a SaveAs file named based on the value of a cell in the work book.

All of this works great. My problem is, if I need to edit a workbook I made using this template Excel will not let me save the file.

Is there a way to delete the VBA code used for the template so it does not transfer over into my .xls document?

thanks
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
Here is the basic code to delete Code modules. You can incorporate it ito your code. When we save a workbook the new becomes the active one.
Code:
'===============================================================
'- DELETE STANDARD & CLASS MODULES FROM A WORKBOOK
'- Checks each one. Message box option to delete or keep
'- Brian Baulsom August 2007
'===============================================================
Sub REMOVE_CODEMODULES()
    Dim MyModule As Object
    '----------------------------------------------------------
    With ActiveWorkbook.VBProject
    For Each MyModule In .vbComponents
        Select Case MyModule.Type
            Case 1, 2 ' standard or class module
                SheetType = "Standard or Class Module"
                SheetName = MyModule.Name
                '---------------------------------------------
                '-
                MsgReply = MsgBox("Remove Code module : " _
                    & SheetName & " ?", vbYesNoCancel)
                If MsgReply = vbCancel Then Exit Sub
                If MsgReply = vbYes Then
                    .vbComponents.Remove MyModule
                End If
                '---------------------------------------------
        End Select
    Next
    End With
End Sub
'==============================================================
 

Watch MrExcel Video

Forum statistics

Threads
1,123,535
Messages
5,602,217
Members
414,513
Latest member
junbuggle

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
Top