Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA how can I stop a Save

I would like to stop users from saving a workbook if a
cells contents have not been completed, I know that I can
use the Event BeforeSave to do a test on the contents of a
cell but how can I stop the save

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean,
Cancel As Boolean)
If Range("C10") = "" Then
MsgBox "Please complete cell C10"
Exit Sub
End If
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA how can I stop a Save

Set the Cancel argument to True. E.g.,


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean,
Cancel As Boolean)
If Range("C10") = "" Then
MsgBox "Please complete cell C10"
Cancel = True
Exit Sub
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"newboy18" wrote in message
...
I would like to stop users from saving a workbook if a
cells contents have not been completed, I know that I can
use the Event BeforeSave to do a test on the contents of a
cell but how can I stop the save

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean,
Cancel As Boolean)
If Range("C10") = "" Then
MsgBox "Please complete cell C10"
Exit Sub
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA how can I stop a Save

Thanks Chip and Frank
Cancel = True


Works just fine
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA how can I stop a Save


Apologies for ressurrecting an old topic.

Ive tried the previous technique for stopping a save when there are
blank cells. Unfortunately due to the nature of the data Iam
requesting, it is not appropriate for me to use the Exit Sub if it has
not been correctly filled in.

Therefore Iam using much the same but as a prompt on saving that there
are gaps in the data. It would appear though that Iam getting the
msgbox twice.

Presumably this is because after Cancel=True Iam calling the SaveAs
box, any ideas how I might get round this?

Code below:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim Blanks As Range
Dim SumBlanks As Double

Set Blanks = Range("aj63:aj263")
SumBlanks = Application.Sum(Blanks)
If SumBlanks 0 Then
MsgBox "There appears to be some missing or invalid data."
Cancel = True
'Exit Sub
End If
Application.Dialogs(xlDialogSaveAs).Show
End Sub


Many thanks,
Eddie


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA how can I stop a Save


Apologies for ressurrecting an old topic.

Ive tried the previous technique for stopping a save when there ar
blank cells. Unfortunately due to the nature of the data Ia
requesting, it is not appropriate for me to use the Exit Sub if it ha
not been correctly filled in.

Therefore Iam using much the same but as a prompt on saving that ther
are gaps in the data. It would appear though that Iam getting th
msgbox twice.

Presumably this is because after Cancel=True Iam calling the SaveA
box, any ideas how I might get round this?

Code below:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel A
Boolean)
Dim Blanks As Range
Dim SumBlanks As Double

Set Blanks = Range("aj63:aj263")
SumBlanks = Application.Sum(Blanks)
If SumBlanks 0 Then
MsgBox "There appears to be some missing or invalid data."
Cancel = True
'Exit Sub
End If
Application.Dialogs(xlDialogSaveAs).Show
End Sub


Many thanks,
Eddi

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default VBA how can I stop a Save

Just set Cancel = true after the message box.

(From the online help:

Syntax
Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As
Boolean)
SaveAsUi True if the Save As dialog box will be displayed.
Cancel False when the event occurs. If the event procedure sets this
argument to True, the workbook isn't saved when the procedure is finished.)

--
HTH -

-Frank Isaacs
Dolphin Technology Corp.
http://vbapro.com





"newboy18" wrote in message
...
I would like to stop users from saving a workbook if a
cells contents have not been completed, I know that I can
use the Event BeforeSave to do a test on the contents of a
cell but how can I stop the save

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean,
Cancel As Boolean)
If Range("C10") = "" Then
MsgBox "Please complete cell C10"
Exit Sub
End If
End Sub



Reply
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
stop prompt to save on no changes made sam2u Excel Discussion (Misc queries) 1 June 2nd 08 09:07 PM
Stop prompting for save the changes in Excel dhardman Excel Discussion (Misc queries) 0 November 28th 07 05:11 PM
Save As - Can I use VBA? to stop XL Sheet overwrite Smudge Excel Discussion (Misc queries) 2 February 8th 07 01:12 AM
Stop asking to save changes Traci Excel Discussion (Misc queries) 3 October 11th 05 03:51 PM
How do I stop excel from asking me if I want to save my document? Jamie Setting up and Configuration of Excel 3 August 12th 05 03:24 AM


All times are GMT +1. The time now is 05:37 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"