Thread: On Close macro
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default On Close macro

Hey Jim,

I can be even pickier :-). Ans should be declared as Long not Integer.

Sorry, just a laugh, couldn't resist.

Regards

Bob

"Jim Thomlinson" wrote in message
...
To be reallllly pick about Bob's code ans should be declared as an

integer.
Without specifying as Bob has done you end up with a variant which

requires
extra overhead. In this application it won't really make any difference

but
it is alway good programming to declare your variable explicitly. This is

a
really picky point but I get people asking me why when they type the dot
after a key word "why they don't get a drop down list". Very often this is
the reason....

dim ans as integer

HTH

"Bob Phillips" wrote:

Hi Judith,

Here is some code

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ans
ans = MsgBox("Are you sure you want tos save this file", vbYesNo)
If ans = vbNo Then
Cancel = True
End If
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--

HTH

RP
(remove nothere from the email address if mailing direct)


"JudithJubilee" wrote in message
...
Hello there,

I have spreadsheets that are updated by various people. I
would like a macro that puts up a message box when they
save or close to ask if they are sure. If they click Yes
then continue. If No then cancels the action.

I'm a beginner in VB but willing to try it!

Judith