How to define/modify a word document path before saveAS

时间:2015-06-22 10:42:51

标签: vba vbscript office-automation word-automation

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

1 个答案:

答案 0 :(得分:2)

始终使用BuildPath构建路径。此外,如果您实际使用VBScript(而不是VBA),则无法在同一步骤中定义变量并为其分配值。此外,带有宏的文档应保存为$('#checkqar').on('click', function() { $("#loading").css("display", "block"); $.ajax({ type: "GET", url: "http://sss.com/eee", crossDomain: true, jsonpCallback: 'callback', contentType: "application/json; charset=utf-8", dataType: "jsonp", success: function(msg) { //do something }, complete: function() { $("#loading").css("display", "none"); // Use it here } }); }); (类型13),而不是.docm(类型15),请参阅WdSaveFormat Enumeration。后一种类型适用于带有宏的文档模板。

这应该有效:

.dotm