Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2006, 02:14 PM
Authorized User
 
Join Date: Mar 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help AFTER saving an Excel File

In Excel 2003, I currently have code that changes the xlCalculation setting to MANUAL (instead of Automatic) at the BEFORESAVE Event of "this workbook". What I'm now looking for is a way to "programmatically" turn the xlCalculation back on once the save is complete.

I haven't been able to find any "AFTER SAVE" or "POST SAVE" events. Does anyone have any ideas? When a user saves the Excel file, I want the calculations "turned off" and when the save is complete, turned back on.

Any help you can provide would be greatly appreciated.

Rick
__________________
Rick
 
Old January 10th, 2006, 02:22 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Rick,

You could cancel the original user prompted save event and do your own as follows:

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    ' Cancel user prompted save procedure ...
    Cancel = True

    ' ... and do our own
    Application.Calculation = xlCalculationManual
    ThisWorkbook.Save
    Application.Calculation = xlCalculationAutomatic

End Sub
 
Old January 10th, 2006, 03:32 PM
Authorized User
 
Join Date: Mar 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maccas,

Thank you sooooo much. This worked perfectly!

Cheers!

Rick
 
Old January 8th, 2007, 01:25 PM
Registered User
 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I've come across a similar problem where I want to perform an operation "after save". I tried the solution you suggested maccas but when the execution reached the "ThisWorkbook.Save" line it invoked the Workbook_BeforeSave method again. Once this was complete it returned to the first invocation of Workbook_BeforeSave and continued through to the end. The problem with this was that the workbook wasn't saved. I am using Excel 2002 as opposed to 2003 which Rick was using though - could this "problem/quirk" have been fixed in 2003?

I created a simple spreadsheet just to ensure that none of my other code was getting in the way and got the same result, this is the code:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True

    MsgBox ("before save")
    ThisWorkbook.Save
    MsgBox ("after save")
End Sub

With this code I saw the "before save" message twice followed by the "after save" message twice.

Thanks,
Nick

 
Old January 8th, 2007, 01:28 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try setting Application.EnableEvents = False as the first line of the sub (Application.EnableEvents = True back on at the end). This will stop Excel registering events whilst you're running your code.

Maccas

 
Old January 8th, 2007, 01:42 PM
Registered User
 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That did the trick nicely.

Thanks for your quick reply.

Nick






Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving with Excel VBA Scooter057 Excel VBA 1 January 15th, 2008 10:33 PM
Saving results as Excel chrscote Classic ASP Databases 3 August 9th, 2007 05:56 PM
Saving Excel File tdaustin Classic ASP Basics 6 December 2nd, 2006 03:38 AM
Saving an excel file in Access VBA theboylatham Access VBA 1 August 19th, 2005 08:14 AM
EXCEL question saving a file saving the the first macupryk VS.NET 2002/2003 0 January 6th, 2005 05:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.