Overriding Macros

manona

New Member
Joined
Mar 22, 2016
Messages
40
Hi,

I currently have a simple macro (see below) that requires users to input values in specific cells, otherwise it will not print or save.

However, I need to be able to leave the values blank before saving and sending to the user.

Any suggestions? I want to be able to save with blank cells, but once the user opens that document, I don't want them to also be able to save it blank (defeats the purpose of the first macro!).

Any help is appreciated, thanks! :)

PS I thought maybe there would be a way to request username and password, and based on username, the macro would override the macro preventing from saving without value in cell. I need to have a log in upon opening of the document anyways; just a thought.

MACRO used:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Sheets("Sheet1").Range("C15").Value = "" Then
MsgBox "C15 requires user input."
Cancel = True 'cancels the save event
Exit Sub
End If
If Sheets("Sheet1").Range("C16").Value = "" Then
MsgBox "C16requires user input."
Cancel = True 'cancels the save event
Exit Sub
End If
End Sub


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Sheets("Sheet1").Range("C15").Value = "" Then
MsgBox "C15 requires user input."
Cancel = True 'cancels the save event
Exit Sub
End If
If Sheets("Sheet1").Range("C16").Value = "" Then
MsgBox "C16requires user input."
Cancel = True 'cancels the save event
Exit Sub
End If
End Sub
Private Sub Workbook_Open()


End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try creating your own Private Sub procedure which disables events, saves the file, then re-enables events, i.e.
Code:
Private Sub MySave()
    Application.EnableEvents = False
    ActiveWorkbook.Save
    Application.EnableEvents = True
End Sub
So, if you save it using this script, it will work.
 
Upvote 0
Thanks Joe4!
I've tried pasting your code below that 2nd macro I have, but it is still not allowing me to save without values.
I'm relatively new at VB; is there anywhere specific I need to put this code?
Thanks for your help and patience :)
 
Upvote 0
I've tried pasting your code below that 2nd macro
You can paste this code in any module you want.
But then to save the file, highlight the first line of this code, then press the Run button from the VB menu.
(You cannot save the file through the normal Save menu like you are used to).
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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