PC Review


Reply
Thread Tools Rate Thread

Cancel Button on file save

 
 
lwm
Guest
Posts: n/a
 
      19th Jan 2008
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


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      19th Jan 2008
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
 
Reply With Quote
 
lwm
Guest
Posts: n/a
 
      19th Jan 2008
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
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      19th Jan 2008
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Allow for user pressing cancel in File/Save API Phil Trumpy Microsoft Access External Data 1 31st Jul 2008 05:41 PM
Disable or hide Cancel button on Save dialog box Sandy Microsoft Excel Programming 3 20th Jun 2008 04:42 PM
File Save, yes, no, cancel macro nuver Microsoft Excel Programming 8 13th Nov 2005 04:10 AM
Cancel Button in Open File Window =?Utf-8?B?U1M=?= Microsoft Excel Programming 1 6th Jun 2005 07:37 PM
Permission failure on save/cancel button press =?Utf-8?B?TmlnZWwgUml2ZXR0?= Microsoft ASP .NET 0 17th Jun 2004 11:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:41 AM.