Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Workbooks.Add and SaveAs don't occur

Hi NG,

In my AddIn I monitor events at an application level (AppEvents As
Excel.Application) in order to trap all the events for certain workbooks.
This works fine.

Within the BeforeSave event, if the passed WB falls into the certain
category, I perform two operations of note before saving the workbook:

(1) - Use wb.SaveCopyAs to create a backup copy. (wb.SaveCopyAs PATH_BACKUP
& "\" & myBackUpFileName)
(2) - Create a "copy for publishing", this uses Workbooks.Add to create a
new workbook, populate it with some data, save it elsewhere.

All of this works very nicely, seamlessly and invisibly under normal
circumstances. Today however, I have a new sub in my AddIn which I don't
want to be run unless the user has saved the workbook so I check this and
then, if the user wishes, save it for them before continuing.
code snippet:
If Not ActiveWorkbook.Saved = True Then
If MsgBox("You cannot perform this if the workbook isn't saved." &
vbCrLf _
& "Do you wish to save and continue?", vbOKCancel + vbQuestion)
= vbOK Then
ActiveWorkbook.Save
Else
Exit Sub
End If
End If

The ActiveWorkbook.Save fires my BeforeSave event that I've trapped - as one
would expect - BUT... the SaveCopyAs code doesn't work. I can just F8 over
the line - there's no error raised (err.number = 0) , it's that no copy is
saved.

Likewise when I create the copy for the publishing I use "Set wbNew =
Workbooks.Add" and, instead of creating a new workbook, it just returns the
activeworkbook as wbNew - which rather messes things up.

Obviously the easiest solution is to just warn the user the activeworkbook
isn't saved and exit the procedure rather than offer to save it for them but
this is not what I want to do... :-(

Has anyone seen this sort of behaviour before? All thoughts gratefully
received

Thanks,
Gareth



Excel 2000 SP-3
Win2000


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
How do I set up an item to re-occur on a spreadsheet? Dhale Excel Worksheet Functions 1 December 29th 08 08:22 PM
Have something occur on scroll GeorgeJ Excel Discussion (Misc queries) 2 August 25th 07 07:56 PM
Return Value If Two Conditions occur Hatman Excel Worksheet Functions 5 January 30th 06 08:34 PM
SaveAs and Hidden Workbooks wtpcomplab Excel Programming 1 December 11th 04 01:27 AM
VBA occur error - kernel32.dll Judy[_4_] Excel Programming 1 August 20th 03 10:43 AM


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