LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default BeforeSave and Close help

To answer your question about where to put your code to check those cells:

In the Select Case block:
Case vbYes
'means the user wants to save the file.
'doing your check here before saving the file will cancel closing the file
With Worksheets("Drawing Notice (Main Sheet) 1")
If .Range("C16").Value = "0" Or .Range("C16").Value = "" _
Or .Range("E16").Value = "1" Or .Range("E16").Value = "" _
Or .Range("G16").Value = "1" Or .Range("G16").Value = "" _
Or .Range("I16").Value = "1" Or .Range("I16").Value = "" _
Or .Range("C17").Value = "" _
Or .Range("F17").Value = "" Then

'display your message
MsgBox "You must complete the highlighted fields."

'set the value being passed to Workbook_BeforeClose() and exit
bBeforeShutDown = True
Exit Function
End If
End With

'If all the cells pass the test then we save.
Wbk.Save
'Placing your test "as is" in the BeforeSave event will handle when the
user saves.
'If the conditions pass your test in either place, normal behavior occurs.
'If the conditions fail the test in either place, the user is returned to
Excel to resume.

As I said previously, I don't normally handle Workbook events from the
ThisWorkbook module. I did earlier on but I switched to using Auto_Open and
Auto_Close procedures and thus, revised all my code snippets accordingly.
That's why the earlier example didn't work for you "as is", ..it was intended
as a suggestion of how you could handle the task. After reading your response
to my reply, I realized you needed more explicit help with it. I hope that
has been accomplished!

Regards,
GS



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
BeforeSave Steven Excel Programming 2 January 21st 06 05:37 PM
BeforeSave question RPIJG[_86_] Excel Programming 7 November 11th 05 06:23 PM
beforesave and beforeclose Adam Harding Excel Programming 2 July 25th 05 11:11 AM
BeforeSave Sub Phil Hageman[_3_] Excel Programming 6 January 14th 04 10:12 AM
VBA - BeforeSave - NEED HELP HRobertson Excel Programming 2 October 23rd 03 06:50 PM


All times are GMT +1. The time now is 02:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"