BeforeSave event

Darchcruise

New Member
Joined
Jun 3, 2011
Messages
8
Hello,

I am new to VBA, and reading a book by John Walkenbach. In page 160 he has a paragraph called "BeforeSave event for a workbook".

Question:
Can someone translate and explain to me what this line of code means in English/simple terms?

(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Thanks
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
so basically, SaveAsUI translates to "Save As User Interface" and Cancel translates into "Cancel" (duh..)

As Boolean describes variables' types which are obviously Booleans.

Booleans are variable types which only allow values of "True" or "False" to be stored in the variable. In VBA, 0 is recognized as False and all the other values are recognized as True.

So, if you have a code like
Code:
Cancel = 0
this would be equivalent as saying
Code:
Cancel = False

Anyways, in this event, if you look to this website:
http://msdn.microsoft.com/en-us/library/aa220840(v=office.11).aspx

SaveAsUI (when set as True) will pop up a save as dialog for the user to choose a directory to save the file in and which format to save the file in..
while if the Cancel is set as True, the saving process will immediately stop, meaning save will never ever happen.
 
Upvote 0
I'm not sure I understand that completely.

Here is the full code:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI _
As Boolean, Cancel As Boolean)
Sheets(“Sheet1”).Range(“A1”).Value = _
Sheets(“Sheet1”).Range(“A1”).Value +1
End Sub

How does the SaveAsUI As Boolean, Cancel As Boolean work in this code?

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
Lawrenceiow

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