Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Use proper SaveAS in Excel (Excel 2003)

    I have a small macro to open a spread sheet from a template and show the SaveAs dialog box.
    The new workbook opens as well as the SaveAs dialog box.
    I enter a new file name and the workbook gets saved with the chosen name but no Extension.
    The SaveAs dialog box only had *.* in the file types window.
    Below are the code lines I picked up from Excel help. What is missing?

    Do
    fName = Application.GetSaveAsFilename
    Loop Until fName <> False
    ActiveWorkbook.SaveAsFilename:=fName

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Use proper SaveAS in Excel (Excel 2003)

    Are you specifiying a file format? From the Help:

    .SaveAs(FileName, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodepage, TextVisualLayout, Local)

    There's a number of FileFormat parameters; you probably want to specify "FileFormat:=xlNormal".
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Use proper SaveAS in Excel (Excel 2003)

    You can specify a file filter in the GetSaveAsFilename function:
    <code>
    fName = Application.GetSaveAsFilename(FileFilter:="Excel workbooks (*.xls), *.xls")</code>

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Use proper SaveAS in Excel (Excel 2003)

    Thank you. That is solved but I just became aware of another.
    The code just loops waiting for the user to enter a file name.
    What extra line can I add to watch for the Cancel button being hit and thus ending the routine?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Use proper SaveAS in Excel (Excel 2003)

    Something like this:

    fName = Application.GetSaveAsFilename(FileFilter:="Excel workbooks (*.xls), *.xls")
    If VarType(fName) = vbBoolean Then
    ' Canceled - get out
    Exit Sub
    End If
    ActiveWorkbook.SaveAs Filename:=fName

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Use proper SaveAS in Excel (Excel 2003)

    Thank you, everything works fine now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •