If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > VB in Excel: Preventing Saving Until A Condition is Met

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-29-04, 08:27
mark_s12 mark_s12 is offline
Registered User
 
Join Date: Mar 2004
Posts: 2
VB in Excel: Preventing Saving Until A Condition is Met

Hi

Im very new to VB and am wondering whether it is possible to prevent users saving a worksheet in excel if a certain condition is not met. Basically if they do not enter text, say in column H, is it possible to prevent them from saving the worksheet. If not, is it possible to bring up a Message Box prompting them to fill in the field?

Any help would be really appreciated,

Mark
Reply With Quote
  #2 (permalink)  
Old 03-29-04, 11:03
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
Re: VB in Excel: Preventing Saving Until A Condition is Met

In the ThisWorkbook Code you can set the Event Handler workbook beforesave such as

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If Range("H65536").End(xlUp).Row = 1 Then
        Cancel = True
    End If
End Sub
this checks if there is anything in any cell in column H bar row 1.
the Cancel = True Cancels the Save Event.

To Get into ThisWorkbook code get into VBA Window (Press Alt+F11)
and Double click on thisworkbook under the Project Explorer.

Hope this Helps

David
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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