none
setting the file name of Word docment in the SAVEAS dialog RRS feed

Answers

  • Hi Jim,

    Here is an example:

    Sub FileSaveAsRoutine()
        Dim fName As String
        With Application.FileDialog(msoFileDialogSaveAs)
            .Title = "Select the directory for where to save the file."
            .InitialFileName = "H:\temp"
            If .Show <> -1 Then
                MsgBox "User aborted save", vbExclamation
                Exit Sub
            End If
            fName = Replace(.SelectedItems(1), ".docx", ".abc")
            ActiveDocument.SaveAs fileName:=fName, AddToRecentFiles:=False
        End With
    End Sub
    

    You set the name with the InitialFileName property. In this example it's relying on the user's save file setting for the save format. If I had wanted to force it to doc or docx then I would have added the extension onto "temp".

    This example is also not using the "Execute" property, which means we are trapping what the user has entered so that we can make an adjustment to the extension.

    Hope this helps


    Kind Regards, Rich ... http://greatcirclelearning.com

    Friday, April 26, 2013 8:51 PM
  • Hi Jim,

    Don't put a path in the initial file name. The dialog will default to the user settings and they can select the path.


    Kind Regards, Rich ... http://greatcirclelearning.com

    Friday, April 26, 2013 9:00 PM

All replies

  • Hi Jim,

    Here is an example:

    Sub FileSaveAsRoutine()
        Dim fName As String
        With Application.FileDialog(msoFileDialogSaveAs)
            .Title = "Select the directory for where to save the file."
            .InitialFileName = "H:\temp"
            If .Show <> -1 Then
                MsgBox "User aborted save", vbExclamation
                Exit Sub
            End If
            fName = Replace(.SelectedItems(1), ".docx", ".abc")
            ActiveDocument.SaveAs fileName:=fName, AddToRecentFiles:=False
        End With
    End Sub
    

    You set the name with the InitialFileName property. In this example it's relying on the user's save file setting for the save format. If I had wanted to force it to doc or docx then I would have added the extension onto "temp".

    This example is also not using the "Execute" property, which means we are trapping what the user has entered so that we can make an adjustment to the extension.

    Hope this helps


    Kind Regards, Rich ... http://greatcirclelearning.com

    Friday, April 26, 2013 8:51 PM
  • Thank you. I forgot to mention that my question was Word 2013 specific which may not make a difference even if the user is selecting a Cloud based storage location like SkyDrive or Office 365 location.
    Friday, April 26, 2013 8:57 PM
  • Hi Jim,

    Don't put a path in the initial file name. The dialog will default to the user settings and they can select the path.


    Kind Regards, Rich ... http://greatcirclelearning.com

    Friday, April 26, 2013 9:00 PM
  • That makes sense, thank you.

    Friday, April 26, 2013 9:04 PM