@@ -43,6 +43,14 @@ if ($outputFilePath.EndsWith(".xltm")) {
4343 $outputFilePath = $outputFilePath -replace " \.xltm$" , " .xltm.xlsm"
4444}
4545
46+ if ($outputFilePath.EndsWith (" .dotm" )) {
47+ $outputFilePath = $outputFilePath -replace " \.dotm$" , " .dotm.docm"
48+ }
49+
50+ if ($outputFilePath.EndsWith (" .potm" )) {
51+ $outputFilePath = $outputFilePath -replace " \.potm$" , " .potm.pptm"
52+ }
53+
4654if ($outputFilePath.EndsWith (" .ppam" )) {
4755 $outputFilePath = $outputFilePath -replace " \.ppam$" , " .ppam.pptm"
4856}
@@ -296,9 +304,23 @@ Write-Host "Saving document..."
296304$oldFilePath = " "
297305try {
298306 if ($officeAppName -eq " Word" ) {
299- # For PowerPoint, use SaveAs with the same file name to force save
300- $doc.SaveAs ($outputFilePath )
301- Write-Host " Document saved using SaveAs method"
307+ # For Word, check if the file name ends with .dotm.docm
308+ # If so, we need to save as .dotm
309+ if ($outputFilePath.EndsWith (" .dotm.docm" )) {
310+ $oldFilePath = $outputFilePath
311+ $outputFilePath = $outputFilePath -replace " \.dotm\.docm$" , " .dotm"
312+ # Replace forward slashes with backslashes
313+ $outputFilePath = $outputFilePath -replace " /" , " \"
314+ Write-Host " Saving document as .dotm: $outputFilePath "
315+ $doc.SaveAs ($outputFilePath , 15 ) # 15 is the wdFormatXMLTemplateMacroEnabled file format for .dotm
316+ # Delete the .dotm.docm file
317+ Remove-Item - Path $oldFilePath - Force
318+ Write-Host " Document saved as .dotm at ${doc.Path} "
319+ } else {
320+ # We just use SaveAs since it's a normal Word document
321+ $doc.SaveAs ($outputFilePath )
322+ Write-Host " Document saved using SaveAs method"
323+ }
302324 } elseif ($officeAppName -eq " PowerPoint" ) {
303325 # For PowerPoint, we need to check if the file name ends with .ppam.pptm
304326 # If so, we need to save as .ppam
@@ -312,6 +334,19 @@ try {
312334 # Delete the .ppam.pptm file
313335 Remove-Item - Path $oldFilePath - Force
314336 Write-Host " Document saved as .ppam"
337+
338+ # Check if the extension is .potm and if so save as .potm
339+ } elseif ($outputFilePath.EndsWith (" .potm.pptm" )) {
340+ $oldFilePath = $outputFilePath
341+ $outputFilePath = $outputFilePath -replace " \.potm\.pptm$" , " .potm"
342+ # Replace forward slashes with backslashes
343+ $outputFilePath = $outputFilePath -replace " /" , " \"
344+ Write-Host " Saving document as .potm: $outputFilePath "
345+ $doc.SaveAs ($outputFilePath , 17 ) # 17 is the ppSaveAsOpenXMLTemplateMacroEnabled file format for .potm
346+ # Delete the .potm.pptm file
347+ Remove-Item - Path $oldFilePath - Force
348+ Write-Host " Document saved as .potm"
349+
315350 } else {
316351 $doc.Save ()
317352 Write-Host " Document saved successfully"
0 commit comments