Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems with BeforeSave and Application.EnableEvents = False

Hello,

I learned in this newsgroup to use the BeforeSave event to force the
user to do specific things when he wants to save the workbook. Well,
this works great. But sometimes I get an error I can't avoid.

If the filename already exists I get the question whether I want to
replace the file. If I decide not to replace the file and choose the
button 'No' or 'Cancel' then I get the run- time error
'1004'.

Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

fname = Application.GetSaveAsFilename

Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:=fname
Application.EnableEvents = True

End Sub

Can anybody give me some hint?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Problems with BeforeSave and Application.EnableEvents = False

do you want this alert. if you dont want try to introduce in the beginning

application.displayalerts=false
and later at the end
application.displayalerts=true

I have not checked this.

Sanne wrote in message
oups.com...
Hello,

I learned in this newsgroup to use the BeforeSave event to force the
user to do specific things when he wants to save the workbook. Well,
this works great. But sometimes I get an error I can't avoid.

If the filename already exists I get the question whether I want to
replace the file. If I decide not to replace the file and choose the
button 'No' or 'Cancel' then I get the run- time error
'1004'.

Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

fname = Application.GetSaveAsFilename

Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:=fname
Application.EnableEvents = True

End Sub

Can anybody give me some hint?





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Problems with BeforeSave and Application.EnableEvents = False

Hi Sanne

Application.DisplayAlerts = False

before you try to do a save, should work.

Regards

Andrew Bourke


Sanne wrote:
Hello,

I learned in this newsgroup to use the BeforeSave event to force the
user to do specific things when he wants to save the workbook. Well,
this works great. But sometimes I get an error I can't avoid.

If the filename already exists I get the question whether I want to
replace the file. If I decide not to replace the file and choose the
button 'No' or 'Cancel' then I get the run- time error
'1004'.

Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

fname = Application.GetSaveAsFilename

Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:=fname
Application.EnableEvents = True

End Sub

Can anybody give me some hint?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problems with BeforeSave and Application.EnableEvents = False

Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim fName as Variant
Dim ans as Long
fname = Application.GetSaveAsFilename
if fName = False then exit sub
If dir(fname) < "" then
ans = msgbox( fname & vbNewline & _
"Already exists. Do you want to replace it? ", _
vbYesNo)
if ans = vbNo then
cancel = true
exit sub
end if
End if
Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:=fname
Application.EnableEvents = True

End Sub


Would be another approach.

--
Regards,
Tom Ogilvy

"Sanne" wrote in message
oups.com...
Hello,

I learned in this newsgroup to use the BeforeSave event to force the
user to do specific things when he wants to save the workbook. Well,
this works great. But sometimes I get an error I can't avoid.

If the filename already exists I get the question whether I want to
replace the file. If I decide not to replace the file and choose the
button 'No' or 'Cancel' then I get the run- time error
'1004'.

Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

fname = Application.GetSaveAsFilename

Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:=fname
Application.EnableEvents = True

End Sub

Can anybody give me some hint?



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
Application.EnableEvents DCPan Excel Worksheet Functions 3 October 18th 08 05:46 AM
application.EnableEvents nc Excel Discussion (Misc queries) 1 September 28th 05 04:00 PM
object.EnableEvents = false Ajit Excel Programming 1 November 3rd 04 09:54 PM
application.enableEvents jeffP Excel Programming 1 August 1st 04 03:12 PM
Application.EnableEvents Terry Excel Programming 2 April 2nd 04 08:25 PM


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