View Single Post
 
Old 08-17-2023, 11:45 AM
David Peck David Peck is offline Windows 10 Office 2021
Novice
 
Join Date: Jun 2023
Posts: 3
David Peck is on a distinguished road
Default instance a new dotm file from a Word dotm file and save with new file name

I'm using this code to test if a file is a new instance just created from a dotm file and if so, saving it to a file with a docm extension.

When I attempt to reopen the file after closing it, Word reports the file as being corrupt.

The second parameter of ActiveDocument.SaveAs is WdSaveFormat - I'm looking at the MS page for WdSaveFormat
SaveAs Method | Microsoft Learn

I do not see a symbolic constant for the docm file type. if I try to set WdSaveFormat to the default (wdFormatDocument) I get a different error saying the file extension does not match.

Question: Seeking a method to instance a new file from a macro enabled template (dotm) and save it as a macro enabled file (docm)



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 WordDocFilePathAndName
End If
Reply With Quote