|
-
May 9th, 2005, 01:54 PM
#1
Thread Starter
Frenzied Member
EXCEL: How To? Prevent abort in SaveAs when file exists ???
Esteemed Forum Participants and Lurkers:
========================================
EXCEL SaveAs Function Returns
I'm doing a SaveAs in my EXCEL VBA program:
aworkbook.SaveAs fileName:="TEST.xls"
If the file already exists, a modal dialog box pops up with the message:
A file named 'TEST.xls' already exists in this location. Do you want to replace it?
... and 3 buttons: Yes No Cancel
If Yes is selected, the program continues normally.
If No or Cancel is selected, the program aborts into MS Visual Basic with the message:
Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed
How can I determine the returns from the No and Cancel buttons and process these returns in my program without having the program abort?
Thank you for your gracious comments, suggestions, and assistance.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
May 9th, 2005, 02:24 PM
#2
Re: EXCEL: How To? Prevent abort in SaveAs when file exists ???
You need to add an error handler and trap for 1004 error.
VB Code:
Private sub command1_click
On error goto myerror
activeworkbook.Save
If activeworkbook.saved = true then
'blah
endif
exit sub
myerror:
if err.number = 1004 then
'canceled
endif
end sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 9th, 2005, 02:30 PM
#3
Thread Starter
Frenzied Member
Re: EXCEL: How To? Prevent abort in SaveAs when file exists ???
RobDog:
Thanks ...
A significant part of the question I was asking: When the error is generated, is there any way to tell which button ... No or Cancel ... was clicked?
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
May 9th, 2005, 02:36 PM
#4
Re: EXCEL: How To? Prevent abort in SaveAs when file exists ???
If your saving the wb as the same name as the activeworkbook then it was in this line.
VB Code:
If activeworkbook.saved = true then
If the .Saved property is true then it was overwritten.
You could also just check for the file's existance before the save and handle it that way.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 9th, 2005, 02:49 PM
#5
Thread Starter
Frenzied Member
Re: EXCEL: How To? Prevent abort in SaveAs when file exists ???
I still can't figure out why there are 2 buttons (besides the "Yes") in the popup ... "No" and "Cancel" ... and what the difference is between them. They both seem to generate the exact same error, so how does one differentiate between them if I want them to program them to have different results?
I know how to program around this, but I am trying to figure out the buttons in this particular modal dialog box.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
May 9th, 2005, 03:14 PM
#6
Re: EXCEL: How To? Prevent abort in SaveAs when file exists ???
I looked deeper into this and I dont see any way (yet) to differenciate between No and Cancel. 
I guess its best just to test for the file existnace first.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 9th, 2005, 03:22 PM
#7
Thread Starter
Frenzied Member
Re: EXCEL: How To? Prevent abort in SaveAs when file exists ???
That makes us even! Thanks for your help. I guess I'll have to program around it for now, but it will bug me until I figure out how to do it.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
May 9th, 2005, 03:26 PM
#8
Re: EXCEL: How To? Prevent abort in SaveAs when file exists ???
I know how you feel, but I think if they havent given us the ability to do it in 2003 that they probably wont anytime soon. 
In Word you can execute a dialog (not shown) and get results, but I tried in Excel but its unsupported.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|