Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Unexplained WorkbookBeforeSave SaveAs Error Causes Excel to Crash

I have created a fairly extensive (for me anyway) code set that will
ultimately become an Excel 2003 addin for my team. We have recently begun an
effort to implement strict ISO requirements for document version control; I'm
trying to automate this process with this future addin. So, what I've done
is created a series of custom fields to contain the required components of my
filenames and am using the code below to automatically update the version &
subsequently save as a new file with the version numbers in the file name.

The only problem is that something about the ActiveWorkbook.SaveAs makes
Excel crash every time it SavesAs a new (because of the changed ver. numbers
appended to the filename) file. Once I restart Excel, everything is fine and
even the new file works just fine.

Strangely enough though, if I manually manipulate the version fields so that
when I save it, it would create a filename of a file that already exists, it
asks me if I wanted to replace, and then everything works fine. Obviously, I
want to create a new file each and every save, but I can't seem to figure out
what's making it crash. The same code also works in 2007 on my PC at home.

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As
Boolean, _
Cancel As Boolean)
Determine
Dim UpdAnswer, Ext As Variant
UpdAnswer = MsgBox("Is this revision a major update?", vbQuestion +
vbYesNoCancel, _
"Version Verification")
Ext = Right(ActiveWorkbook.Name, 4)
If UpdAnswer = vbCancel Then
Exit Sub
ElseIf UpdAnswer = vbYes Then
ActiveWorkbook.CustomDocumentProperties("MajNo") = _
ActiveWorkbook.CustomDocumentProperties("MajNo") + 1
ActiveWorkbook.CustomDocumentProperties("MinNo") = 0
ElseIf UpdAnswer = vbNo Then
ActiveWorkbook.CustomDocumentProperties("MinNo") = _
ActiveWorkbook.CustomDocumentProperties("MinNo") + 1
End If
Application.EnableEvents = False
ActiveWorkbook.SaveAs (ActiveWorkbook.Path & "\" &
ActiveWorkbook.CustomDocumentProperties("DocName") & _
"_v" & ActiveWorkbook.CustomDocumentProperties("MajNo") & "." & _
ActiveWorkbook.CustomDocumentProperties("MinNo") & Ext)
Application.EnableEvents = True
Cancel = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Unexplained WorkbookBeforeSave SaveAs Error Causes Excel to Crash

First, I wouldn't rely on the workbook you're saving being the activeworkbook.

Since you're tying into that App_WorkbookBeforeSave and passing the workbook
(via the wb parm), I'd use:

wb.custom...
instead of
ActiveWorkbook.Custom...
(for all those activeworkbook references)

If you want to stop the "are you sure you want to overwrite" prompts:

application.displayalerts = false 'added
Application.EnableEvents = False
wb.SaveAs wb.Path & "\" & wb.CustomDocumentProperties("DocName") & _
"_v" & wb.CustomDocumentProperties("MajNo") & "." & _
wb.CustomDocumentProperties("MinNo") & Ext
Application.EnableEvents = True
application.displayalerts = true 'added

(No need for parentheses around the filename in the .SaveAs line, either.)

But I don't think will stop excel from crashing.

I don't have a guess for that.

JT Klipfer wrote:

I have created a fairly extensive (for me anyway) code set that will
ultimately become an Excel 2003 addin for my team. We have recently begun an
effort to implement strict ISO requirements for document version control; I'm
trying to automate this process with this future addin. So, what I've done
is created a series of custom fields to contain the required components of my
filenames and am using the code below to automatically update the version &
subsequently save as a new file with the version numbers in the file name.

The only problem is that something about the ActiveWorkbook.SaveAs makes
Excel crash every time it SavesAs a new (because of the changed ver. numbers
appended to the filename) file. Once I restart Excel, everything is fine and
even the new file works just fine.

Strangely enough though, if I manually manipulate the version fields so that
when I save it, it would create a filename of a file that already exists, it
asks me if I wanted to replace, and then everything works fine. Obviously, I
want to create a new file each and every save, but I can't seem to figure out
what's making it crash. The same code also works in 2007 on my PC at home.

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As
Boolean, _
Cancel As Boolean)
Determine
Dim UpdAnswer, Ext As Variant
UpdAnswer = MsgBox("Is this revision a major update?", vbQuestion +
vbYesNoCancel, _
"Version Verification")
Ext = Right(ActiveWorkbook.Name, 4)
If UpdAnswer = vbCancel Then
Exit Sub
ElseIf UpdAnswer = vbYes Then
ActiveWorkbook.CustomDocumentProperties("MajNo") = _
ActiveWorkbook.CustomDocumentProperties("MajNo") + 1
ActiveWorkbook.CustomDocumentProperties("MinNo") = 0
ElseIf UpdAnswer = vbNo Then
ActiveWorkbook.CustomDocumentProperties("MinNo") = _
ActiveWorkbook.CustomDocumentProperties("MinNo") + 1
End If
Application.EnableEvents = False
ActiveWorkbook.SaveAs (ActiveWorkbook.Path & "\" &
ActiveWorkbook.CustomDocumentProperties("DocName") & _
"_v" & ActiveWorkbook.CustomDocumentProperties("MajNo") & "." & _
ActiveWorkbook.CustomDocumentProperties("MinNo") & Ext)
Application.EnableEvents = True
Cancel = True
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Unexplained WorkbookBeforeSave SaveAs Error Causes Excel to Cr

Thanks Dave,

Noted on the wb usage; actually, my requirements grew into a little more of
a robust functionality that I solved by implementing a custom user form.
When executing through that means, I don't seem to have any problems. Thanks
again for your help!--JT

"Dave Peterson" wrote:

First, I wouldn't rely on the workbook you're saving being the activeworkbook.

Since you're tying into that App_WorkbookBeforeSave and passing the workbook
(via the wb parm), I'd use:

wb.custom...
instead of
ActiveWorkbook.Custom...
(for all those activeworkbook references)

If you want to stop the "are you sure you want to overwrite" prompts:

application.displayalerts = false 'added
Application.EnableEvents = False
wb.SaveAs wb.Path & "\" & wb.CustomDocumentProperties("DocName") & _
"_v" & wb.CustomDocumentProperties("MajNo") & "." & _
wb.CustomDocumentProperties("MinNo") & Ext
Application.EnableEvents = True
application.displayalerts = true 'added

(No need for parentheses around the filename in the .SaveAs line, either.)

But I don't think will stop excel from crashing.

I don't have a guess for that.

JT Klipfer wrote:

I have created a fairly extensive (for me anyway) code set that will
ultimately become an Excel 2003 addin for my team. We have recently begun an
effort to implement strict ISO requirements for document version control; I'm
trying to automate this process with this future addin. So, what I've done
is created a series of custom fields to contain the required components of my
filenames and am using the code below to automatically update the version &
subsequently save as a new file with the version numbers in the file name.

The only problem is that something about the ActiveWorkbook.SaveAs makes
Excel crash every time it SavesAs a new (because of the changed ver. numbers
appended to the filename) file. Once I restart Excel, everything is fine and
even the new file works just fine.

Strangely enough though, if I manually manipulate the version fields so that
when I save it, it would create a filename of a file that already exists, it
asks me if I wanted to replace, and then everything works fine. Obviously, I
want to create a new file each and every save, but I can't seem to figure out
what's making it crash. The same code also works in 2007 on my PC at home.

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As
Boolean, _
Cancel As Boolean)
Determine
Dim UpdAnswer, Ext As Variant
UpdAnswer = MsgBox("Is this revision a major update?", vbQuestion +
vbYesNoCancel, _
"Version Verification")
Ext = Right(ActiveWorkbook.Name, 4)
If UpdAnswer = vbCancel Then
Exit Sub
ElseIf UpdAnswer = vbYes Then
ActiveWorkbook.CustomDocumentProperties("MajNo") = _
ActiveWorkbook.CustomDocumentProperties("MajNo") + 1
ActiveWorkbook.CustomDocumentProperties("MinNo") = 0
ElseIf UpdAnswer = vbNo Then
ActiveWorkbook.CustomDocumentProperties("MinNo") = _
ActiveWorkbook.CustomDocumentProperties("MinNo") + 1
End If
Application.EnableEvents = False
ActiveWorkbook.SaveAs (ActiveWorkbook.Path & "\" &
ActiveWorkbook.CustomDocumentProperties("DocName") & _
"_v" & ActiveWorkbook.CustomDocumentProperties("MajNo") & "." & _
ActiveWorkbook.CustomDocumentProperties("MinNo") & Ext)
Application.EnableEvents = True
Cancel = True
End Sub


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Unexplained WorkbookBeforeSave SaveAs Error Causes Excel to Cr

I think that's a better approach, too.

I think making a dedicated macro/userform to do something like this makes a lot
more sense.

JT Klipfer wrote:

Thanks Dave,

Noted on the wb usage; actually, my requirements grew into a little more of
a robust functionality that I solved by implementing a custom user form.
When executing through that means, I don't seem to have any problems. Thanks
again for your help!--JT

"Dave Peterson" wrote:

First, I wouldn't rely on the workbook you're saving being the activeworkbook.

Since you're tying into that App_WorkbookBeforeSave and passing the workbook
(via the wb parm), I'd use:

wb.custom...
instead of
ActiveWorkbook.Custom...
(for all those activeworkbook references)

If you want to stop the "are you sure you want to overwrite" prompts:

application.displayalerts = false 'added
Application.EnableEvents = False
wb.SaveAs wb.Path & "\" & wb.CustomDocumentProperties("DocName") & _
"_v" & wb.CustomDocumentProperties("MajNo") & "." & _
wb.CustomDocumentProperties("MinNo") & Ext
Application.EnableEvents = True
application.displayalerts = true 'added

(No need for parentheses around the filename in the .SaveAs line, either.)

But I don't think will stop excel from crashing.

I don't have a guess for that.

JT Klipfer wrote:

I have created a fairly extensive (for me anyway) code set that will
ultimately become an Excel 2003 addin for my team. We have recently begun an
effort to implement strict ISO requirements for document version control; I'm
trying to automate this process with this future addin. So, what I've done
is created a series of custom fields to contain the required components of my
filenames and am using the code below to automatically update the version &
subsequently save as a new file with the version numbers in the file name.

The only problem is that something about the ActiveWorkbook.SaveAs makes
Excel crash every time it SavesAs a new (because of the changed ver. numbers
appended to the filename) file. Once I restart Excel, everything is fine and
even the new file works just fine.

Strangely enough though, if I manually manipulate the version fields so that
when I save it, it would create a filename of a file that already exists, it
asks me if I wanted to replace, and then everything works fine. Obviously, I
want to create a new file each and every save, but I can't seem to figure out
what's making it crash. The same code also works in 2007 on my PC at home.

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As
Boolean, _
Cancel As Boolean)
Determine
Dim UpdAnswer, Ext As Variant
UpdAnswer = MsgBox("Is this revision a major update?", vbQuestion +
vbYesNoCancel, _
"Version Verification")
Ext = Right(ActiveWorkbook.Name, 4)
If UpdAnswer = vbCancel Then
Exit Sub
ElseIf UpdAnswer = vbYes Then
ActiveWorkbook.CustomDocumentProperties("MajNo") = _
ActiveWorkbook.CustomDocumentProperties("MajNo") + 1
ActiveWorkbook.CustomDocumentProperties("MinNo") = 0
ElseIf UpdAnswer = vbNo Then
ActiveWorkbook.CustomDocumentProperties("MinNo") = _
ActiveWorkbook.CustomDocumentProperties("MinNo") + 1
End If
Application.EnableEvents = False
ActiveWorkbook.SaveAs (ActiveWorkbook.Path & "\" &
ActiveWorkbook.CustomDocumentProperties("DocName") & _
"_v" & ActiveWorkbook.CustomDocumentProperties("MajNo") & "." & _
ActiveWorkbook.CustomDocumentProperties("MinNo") & Ext)
Application.EnableEvents = True
Cancel = True
End Sub


--

Dave Peterson


--

Dave Peterson
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
#N/A Error unexplained John C[_2_] Excel Worksheet Functions 1 August 21st 08 06:58 PM
Unexplained "Bad Record Length" error / bug? Dave[_66_] Excel Programming 0 April 10th 06 04:24 PM
Excel XP and WorkbookBeforeSave Dave McL. Excel Programming 2 December 5th 05 05:08 AM
Excel crash error code Ed[_17_] Excel Programming 1 February 16th 04 10:46 AM
VBA Compiler Error Cause Excel to Crash MWE[_12_] Excel Programming 3 January 26th 04 02:22 AM


All times are GMT +1. The time now is 10:46 PM.

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

About Us

"It's about Microsoft Excel"