No announcement yet.

Specify the file format I want the file to save as.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Specify the file format I want the file to save as.

    I've got a Macro that opens a Stability file and reformats that file and then gets the save-as name based off of certain parameters in the stability file. Sometimes we have more than 1 Stability file with the same parameters and it wants to save over the original file.
    Instead, I want a box to pop up so the user can name the file what he wants. Ive got this all to work so far.
    What I need, is to specify the file format so that when the user saves the file, its .xlsm. Right now it defaults to .txt. How do I go about getting the save-as box to pop up already in .xlsm file format?

        runNum = wbSource.Worksheets(1).Range("B3").Value  'Gets Run Number from Stability File
        runStr = "Run #" & runNum
        saveAsName = wbSource.Worksheets(1).Range("B2").Text ' using test file as filename
        saveAsName = saveAsName & " " & runStr   
        On Error Resume Next
            wbTarget.SaveAs wbSource.Path & "/" & saveAsName & ".xlsm", FileFormat:=52
        If Err.Number <> 0 Then
            wbTarget.SaveAs Application.GetSaveAsFilename' This is where it opens up as .txt format but I want it to default to .xlsm
        End If
        On Error GoTo 0

  • #2
    The other option which seems more complicated to me but instead of having the user name the file if the original is taken, would be to have an "a" added to the original file name and then a "b" and so on and so forth. So it does it all automatically.


    • #3

      Okay I figured out how to specify the save as format

      wbTarget.SaveAs Application.GetSaveAsFilename(filefilter:="Excel Macro-Enabled Workbook (*.xlsm), *.xlsm")