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

JLGWhiz:

Thanks for your response.
I tried your code, and got an error msg:

Run-time error '1004':
Cannot change part of a merged cell.

E59 is a merged cell, consisting of cells originally E59 thru O59 inclusive.
When I hit the Debug button within the err-msg window, the VB editor window
opened, and line 2 of your code was highlighted.

Also, it is my intent that the user name remain in the saved file, in
addition to appearing on the hardcopy.

"JLGWhiz" wrote:

If you put this code in the ThisWorkbook code module, it will clear the E59
cell for each user as the workbook opens.

Private Sub Workbook_Open()
Range("E59").ClearContents
End Sub

Open the VB editor and right click the ThisWorkbook listed in the project
window. Click View Code and paste the above snippet into the code window.
Then you can enter something in E59 to get it to save the file and when the
workbook opens it will automatically clear that cell. If I recall your
original post correctly, you only want the name there for print out which
occurs after the save event. If I am correct then this addition should allow
you to enter something in E59 to save your prototype file, which will be
removed upon the next opening of the file.


"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