Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default VBA Question - Canceling a 'Save As' command from a user form

Hi V-Man,

A few things you can do here. If the user clicks Cancel, then
GetSaveAsFilename will return False. So if you set up your variable as a
Variant, you can check for that. If the user is prompted to overwrite and
clicks No, VBA will raise a runtime error. So you can ignore that error if
you'd like.

Here's an example:

Private Sub SaveButton_Click()
Dim vName As Variant

On Error GoTo ErrHandler

vName = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls, Text Files" & _
"(*.txt), *.txt, All Files (*.*), *.*")

If Not vName = False Then
ActiveWorkbook.SaveAs Filename:=CStr(vName)
End If

ExitRoutine:
Exit Sub
ErrHandler:
If Err.Number < 1004 Then
MsgBox "Unexpected error." & vbLf & CStr(Err.Number) & _
": " & Err.Description, vbExclamation, "Error"
End If
Resume ExitRoutine
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


V-Man wrote:
Hi all,

I have built a user form in VBA that allows a user to enter and save
data in a template. This data is saved on Sheet 1 of my workbook. I
created a 'save' button on my template that works just fine until the
user is asked if they want to replace a current copy of the file. If
the user clicks 'no', then I get one of two responses: 1) it saves my
file as 'FALSE' or it generates a 1004 run time error.

Here is the code for my save button:

Private Sub SaveButton_Click()
fName = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls, Text Files (*.txt),
*.txt, All Files (*.*), *.*")
ActiveWorkbook.SaveAs Filename:=fName

End Sub

Any suggestions?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Question - Canceling a 'Save As' command from a user form

Jake - you the man! Worked perfectly - thanks for the help..

----- Jake Marx wrote: ----

Hi V-Man

A few things you can do here. If the user clicks Cancel, the
GetSaveAsFilename will return False. So if you set up your variable as
Variant, you can check for that. If the user is prompted to overwrite an
clicks No, VBA will raise a runtime error. So you can ignore that error i
you'd like

Here's an example

Private Sub SaveButton_Click(
Dim vName As Varian

On Error GoTo ErrHandle

vName = Application.GetSaveAsFilename(
fileFilter:="Excel Files (*.xls), *.xls, Text Files" &
"(*.txt), *.txt, All Files (*.*), *.*"

If Not vName = False The
ActiveWorkbook.SaveAs Filename:=CStr(vName
End I

ExitRoutine
Exit Su
ErrHandler
If Err.Number < 1004 The
MsgBox "Unexpected error." & vbLf & CStr(Err.Number) &
": " & Err.Description, vbExclamation, "Error
End I
Resume ExitRoutin
End Su

--
Regards

Jake Mar
MS MVP - Exce
www.longhead.co

[please keep replies in the newsgroup - email address unmonitored


V-Man wrote
Hi all
I have built a user form in VBA that allows a user to enter and sav

data in a template. This data is saved on Sheet 1 of my workbook.
created a 'save' button on my template that works just fine until th
user is asked if they want to replace a current copy of the file. I
the user clicks 'no', then I get one of two responses: 1) it saves m
file as 'FALSE' or it generates a 1004 run time error
Here is the code for my save button
Private Sub SaveButton_Click(

fName = Application.GetSaveAsFilename(
fileFilter:="Excel Files (*.xls), *.xls, Text Files (*.txt)
*.txt, All Files (*.*), *.*"
ActiveWorkbook.SaveAs Filename:=fNam
End Su
Any suggestions



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default VBA Question - Canceling a 'Save As' command from a user form

V-Man wrote:
Jake - you the man! Worked perfectly - thanks for the help...


Maybe, but you da V-Man! <g

No problem - glad to help.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
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
User Form question ah Excel Discussion (Misc queries) 1 November 5th 07 10:40 AM
User form Command Buttons jhyatt Excel Discussion (Misc queries) 3 September 25th 07 04:28 PM
User form and Command button Marilyn Excel Discussion (Misc queries) 3 May 9th 07 12:50 AM
Command Button on User form for Printing Anthony Slater Excel Discussion (Misc queries) 2 September 7th 05 02:01 PM
User form question Gareth[_3_] Excel Programming 1 October 29th 03 06:07 PM


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