I am writing a VBScript that will preform some auto conversion of word documents from .doc to either .docx or .dotm depending if the .doc has any VBA script embedded into the document.
The only trouble im having is modifying the File.Path
I can append the "x" to the tail of the existing path which staifys my requirment for creating the docx, but trying to modify the path to change the extension from doc to dotm is proving to be quite hard to solve.
Is there anyway to define a new FileSystem Path object?
My current thoughts are to use the FileSystemObject Data available. (filename, parentfolder ect) and build a new path to pass into the the SaveAs method.
For Each oFile In oFldr.Files
If LCase(oFSO.GetExtensionName(oFile.Name)) = "doc" Then
Set oDoc = oWord.Documents.Open(oFile.path)
Dim parentFolder = oFSO.GetParentFolderName(oFile)
Dim baseFileName = oFSO.GetBaseName(oFile)
If oDoc.HasVBProject Then
oWord.ActiveDocument.SaveAs parentFolder & baseFileName & ".dotm", 15
Else
oWord.ActiveDocument.SaveAs oFile.path & "x", 12
End If
oDoc.Close
End If
Next
Always use
BuildPath
for constructing paths. Also, if you're actually using VBScript (not VBA) you cannot define a variable and assign a value to it in the same step. Plus, documents with macros should be saved as.docm
(type 13), not as.dotm
(type 15), seeWdSaveFormat
Enumeration. The latter type is for document templates with macros.This should work: