Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
User Form question | Excel Discussion (Misc queries) | |||
User form Command Buttons | Excel Discussion (Misc queries) | |||
User form and Command button | Excel Discussion (Misc queries) | |||
Command Button on User form for Printing | Excel Discussion (Misc queries) | |||
User form question | Excel Programming |