Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
lwm lwm is offline
external usenet poster
 
Posts: 38
Default Cancel Button on file save

Using this code


NewName = InputBox(prompt:="File Name and Directory", Default:=FName)

ActiveWorkbook.SaveAs Filename:=NewName, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False, AddToMru:=True

When the user presses the cancel key the macro fails. What do I add to get
it to just end the sub.

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cancel Button on file save

You could just overwrite any existing file:

newname = inputbox(...)

application.displayalerts = false
activeworkbook.saveas ...
application.displayalerts = true

to allow the user to cance if there's an existing file:

newname = inputbox(...)
on error resume next
activeworkbook.saveas ...
if err.number < 0 then
msgbox "something bad happened"
err.clear
end if
on error goto 0

'keep going....

==========
You may want to look at application.getsaveasfilename in VBA's help. It can
eliminate a lot of typing errors by the user and a lot of validation checks for
you the developer. (Instead of an inputbox.)

lwm wrote:

Using this code


NewName = InputBox(prompt:="File Name and Directory", Default:=FName)

ActiveWorkbook.SaveAs Filename:=NewName, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False, AddToMru:=True

When the user presses the cancel key the macro fails. What do I add to get
it to just end the sub.

Thanks


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
lwm lwm is offline
external usenet poster
 
Posts: 38
Default Cancel Button on file save

Thanks Dave

I am doing a begginer class for non techical peolpe on simple macros so I am
trying to use recorded macro's and them make minor easy to explain changes.
:-)

Which means it is not so easy for me sometimes.

"Dave Peterson" wrote:

You could just overwrite any existing file:

newname = inputbox(...)

application.displayalerts = false
activeworkbook.saveas ...
application.displayalerts = true

to allow the user to cance if there's an existing file:

newname = inputbox(...)
on error resume next
activeworkbook.saveas ...
if err.number < 0 then
msgbox "something bad happened"
err.clear
end if
on error goto 0

'keep going....

==========
You may want to look at application.getsaveasfilename in VBA's help. It can
eliminate a lot of typing errors by the user and a lot of validation checks for
you the developer. (Instead of an inputbox.)

lwm wrote:

Using this code


NewName = InputBox(prompt:="File Name and Directory", Default:=FName)

ActiveWorkbook.SaveAs Filename:=NewName, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False, AddToMru:=True

When the user presses the cancel key the macro fails. What do I add to get
it to just end the sub.

Thanks


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cancel Button on file save

One common task is to open an existing file or to save a file with a new name.

You can record the action, but that recorded macro will have the names embedded
into the recorded macro.

One of the things you may want to include in your task is a way of getting the
name of the file to open (application.getopenfilename) and a way of getting the
name of file to save (application.getsaveasfilename).

Those commands can be incorporated into recorded code that really increases the
functionality of the macro.



lwm wrote:

Thanks Dave

I am doing a begginer class for non techical peolpe on simple macros so I am
trying to use recorded macro's and them make minor easy to explain changes.
:-)

Which means it is not so easy for me sometimes.

"Dave Peterson" wrote:

You could just overwrite any existing file:

newname = inputbox(...)

application.displayalerts = false
activeworkbook.saveas ...
application.displayalerts = true

to allow the user to cance if there's an existing file:

newname = inputbox(...)
on error resume next
activeworkbook.saveas ...
if err.number < 0 then
msgbox "something bad happened"
err.clear
end if
on error goto 0

'keep going....

==========
You may want to look at application.getsaveasfilename in VBA's help. It can
eliminate a lot of typing errors by the user and a lot of validation checks for
you the developer. (Instead of an inputbox.)

lwm wrote:

Using this code


NewName = InputBox(prompt:="File Name and Directory", Default:=FName)

ActiveWorkbook.SaveAs Filename:=NewName, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False, AddToMru:=True

When the user presses the cancel key the macro fails. What do I add to get
it to just end the sub.

Thanks


--

Dave Peterson


--

Dave Peterson
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
File Save, yes, no, cancel macro nuver[_8_] Excel Programming 8 November 13th 05 04:10 AM
Capturing Cancel button on save file dialogue Tanveer_asim Excel Programming 1 August 24th 05 12:56 PM
How to CANCEL file SAVE PROMPT when MACRO is running? Stuart Macro Muppet Excel Discussion (Misc queries) 3 August 11th 05 12:26 PM
Cancel Button in Open File Window SS Excel Programming 1 June 6th 05 07:37 PM
How check for No/Cancel Button when SaveAs and file already exists? Joe HM Excel Programming 7 April 19th 05 10:53 AM


All times are GMT +1. The time now is 05:13 AM.

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"