VBA code that will comment out other vba code?

SURFER349

Board Regular
Joined
Feb 22, 2017
Messages
50
So I've got a worbook made for others to use that has the "save" disabled, to preserve the workbook.

I'd like to make a button or something that will open the 'save as' command but also comment out/disable the 'save disable' code, that way, they can save-as a new file in their own folder and not have to deal w/ the blocking.

Is this possible?

Here's what I'm using, placed on "ThisWorkbook" object.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If Not SaveAsUI Then
        Cancel = True
        MsgBox "To preserve workbook integretiy, 'SAVE' is disabled." & vbNewLine & "Please use 'SAVE AS' to your personal folder.", _
        vbInformation, "Hello!" 'box title
    End If
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Is this what you'd like
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim Fname As String
    If Not SaveAsUI Then
      Cancel = True
      Fname = Application.GetSaveAsFilename(, "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm", , "Save As xlsm file")
      If Fname <> "False" Then
        Application.EnableEvents = False
        ActiveWorkbook.SaveAs Fname, 52
        Application.EnableEvents = True
      Else
        MsgBox "Cancelled"
        Cancel = True
        Exit Sub
      End If
    End If
End Sub
 
Upvote 0
Is this what you'd like

Kinda. It looks like this replaces the Control-S command w/ a save as command. but the vba script is still active. so a user must constantly keep saving as.

Ideally, I'd like something that when run (perform the 'save as your own' button), it disables/comments out the blocking script.

Is this possible?
 
Upvote 0
Why not just make the original workbook read-only? Or a template, for which the default action is New rather than Open?
 
Upvote 0
Why not just make the original workbook read-only? Or a template, for which the default action is New rather than Open?

if its read only, then macros that do a lot of editing, formating, manipulation does not work.

also, anyone can just click "edit anyway" and then resave over it.

not sure what template means or how to make that happen.

So is there no way to script VBA to comment out other parts of the vba?
 
Upvote 0
Do you have any other code in the ThisWorkbook module?
 
Upvote 0
if its read only, then macros that do a lot of editing, formating, manipulation does not work.
Why do you think that?

also, anyone can just click "edit anyway" and then resave over it.
Not if it's opened read-only.

not sure what template means or how to make that happen.
Save it as an xltm file.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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