LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Code in ThisWorkbook crashes Excel

Hi Pat,

A few things I can think of to try, as shown in the modified event
procedure below. First, disable event handling while your save code is
running so as not to end up calling the BeforeSave event recursively.
Second, get rid of Application.Run and call the procedure directly (I'm
assuming it's in the same workbook, so Application.Run shouldn't be
required). Third, since your code is saving the workbook, why not just
cancel Excel's save, if that's what's causing it to crash, by setting the
Cancel argument to True.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
''' Cancel Excel's save and replace it with yours.
Cancel = True
''' This ensures that event handling is
''' restored in case of an error.
On Error GoTo ErrorExit
Application.EnableEvents = False
DualSave
ErrorExit
Application.EnableEvents = True
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Pat Beck" wrote in message
...
Hi, John. I left out the code in hopes I was committing an obvious error
<g, also I may have to simplify it or add elaboration for others to
understand it. If need be, I'll do that and post it.

To clarify, I coded only a call to another sub in the SaveBefore workbook
event using:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Application.Run ("DualSave")
End Sub

Does that part look right?

I noticed from testing that the crash occurs, not during the execution of

my
code added to the SaveBefore event, but when it is finished and Excel
proceeds to do its normal save it crashes. So, it does not seem to like
saving to an FTP site, then saving as the same original file

(over-writing)
to my hard drive, then doing its normal save.

I can see how it could get confused, but do not know what to do about it.
Any ideas?

Thanks,
Pat


As you didn't post the code that you were using, it's difficult to
attempt to diagnose what might be wrong with it.
As a rule, I *never* actually code anything directly in the Workbook
Events other than a call to another sub. Makes testing a lot easier
and I don't have to worry if it's the *event* that's causing the problem
since I can just add a MsgBox to the event (for testing purposes)
just to see if/when it's firing.

John


"Pat Beck" wrote in message
...
Excel 2002
WindowsXP

I have a macro in a module that works great when ran directly. But

when
I
run it from ThisWorkbook on a BeforeSave event it crashes Excel

constantly.
Basically, the macro saves to an FTP site as well as the hard drive

when
the
user saves. I can have the user hit a macro button to run my
saveFTP/saveHardDrive macro directly and everything is great, but I'd

like
to launch this action upon a normal save as well. But, like I said,

calling
it up in BeforeSave crashes Excel.

I've had other projects become unstable when I called a macro from

within
ThisWorkbook. So, I must be doing something consistently wrong. I shy

away
from adding any code at all to ThisWorkbook because of my experiences.

Maybe
I'm doing something wrong that can easily be corrected?

Does anyone have ideas or do I need to furnish the exact code?

Thanks,
Pat Beck













 
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
2007 View Code ThisWorkbook KC hotmail com> Excel Discussion (Misc queries) 2 February 24th 10 09:07 PM
Programatically adding macro to Excel - "ThisWorkbook" Aerojade Excel Discussion (Misc queries) 3 October 1st 08 12:53 PM
ThisWorkbook of personal.xls Jack Sons Excel Discussion (Misc queries) 4 August 29th 07 04:28 PM
Code crashes after clearing comments L. Howard Kittle Excel Worksheet Functions 2 February 20th 06 04:54 AM
ThisWorkbook Macros Random Excel Programming 1 August 16th 03 04:03 PM


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