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? |
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 |