View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Ker_01 Ker_01 is offline
external usenet poster
 
Posts: 100
Default CATCH-22 won't let me save the file

Excellent suggestions for the OP (especially turning off events).

One additional one- extension of JLGWhiz's response; rather than always
deleting the contents of the target cell during the workbook open event,
check it for a specific string (such as "Patrick Riley" or "Erase Me") and
only clear that cell during the workbook open event if the target cell
contains your specified string.

Best,
Keith

"Dave Peterson" wrote in message
...
Before you (as the developer, not the user) save the file, you can turn
off
events.

Open the VBE
hit ctrl-g to see the immediate window
type this and hit enter:
application.enableevents = false

Then save your workbook--the _beforesave event won't fire.

Then back to the VBE and toggle the setting in the immediate window:
application.enableevents = true

====
You could also do other stuff, too. Maybe check the username?

if lcase(application.username) = lcase("Patrick Riley") then
'do nothing, let it save...
'or clear that cell!
me.sheets("Main").range("e59").value = ""
else
If IsEmpty(me.Sheets("Main").Range("E59").Value) Then
MsgBox "You must type in your name before " & _
"this file can be saved.", 16, "ERROR"
Cancel = True
End If
end if



Patrick Riley wrote:

Thanks to some generous help from users of this site, I, with no Visual
Basic
knowledge, am using some VB code that requires the user to type his/her
name
into a given cell before the file can be saved, since the name must
appear on
the printed version. The user-name field is intentionally left blank.
Upon
attempting to save, the code presents a message to type in the name, if
the
name-field is still blank.
Well, CATCH-22. This very code is preventing me from leaving the name
field
blank when I try to save the file in final form, ready for enduser use.
The code I am using is:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
If IsEmpty(Sheets("Main").Range("E59").Value) Then
MsgBox "You must type in your name before " & _
"this file can be saved.", 16, "ERROR"
Cancel = True
End If
End Sub

Any suggestions?
---Pat Riley


--

Dave Peterson