View Single Post
 
Old 08-18-2023, 02:28 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The available fileformats are listed at WdSaveFormat enumeration (Word) | Microsoft Learn. Your macro has three issues. One is attributable to not observing good practice i.e. you have not declared the variables used, the others relate to the file naming.
Your variable selectedTargetPath does not include the path separator, so the probability is that the chosen path does not exist, when included in your WordDocFilePathAndName.
By default Word will save an unsaved document as docx format. If you want another format you have to tell it what format you require. In the case of DOCM format that would be wdFormatXMLDocumentMacroEnabled, or its numeric equivalent 13.

NOTE: documents saved as macro enabled will not contain the macros from the template on which they are based. If you want macros, you would have to add them before saving.

Code:
Dim fldr As FileDialog
Dim selectedTargetPath As String
Dim WordDocFilePathAndName As String
Dim saveDate As Date

    If IsNull(ActiveDocument.path) Or ActiveDocument.path = "" Then
        'GET WORKING FOLDER FROM USER
        Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
        With fldr

            .Title = "Select a Folder for this Word File and all of the associated Images to be stored"
            .AllowMultiSelect = False
            If .Show <> -1 Then
                'NOTHING SELECTED NEED MSG
                MsgBox "You must specify a Folder for this Word file to be stored", vbOKOnly + vbExclamation, "FOLDER NOT SELECTED"
                Exit Sub
            Else
                'PATH IS SELECTED
                selectedTargetPath = .SelectedItems(1) & "\"
            End If
        End With
        Set fldr = Nothing

        saveDate = Now

        'SAVE FILE TO FIX ACTIVE DOCUMENT PATH SO FILES CAN BE COPIED TO THE CORRECT LOCATION
        WordDocFilePathAndName = selectedTargetPath & "" & _
                                 "8_5x11 Photos " & Year(saveDate) & "." & Month(saveDate) & "." & Day(saveDate) & _
                                 " " & Hour(saveDate) & "." & Minute(saveDate) & "." & Second(saveDate) & ".docm"
        ActiveDocument.SaveAs FileName:=WordDocFilePathAndName, FileFormat:=wdFormatXMLDocumentMacroEnabled
    End If
    Set fldr = Nothing
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote