宏在 Word 2013 中有效,但在 2010 中无效

Macro works in Word 2013, but not in 2010

我想为我的同事创建一个模板并创建一个 "Saves As.." 到特定文件的宏,并且还使用标题来建议名称。

宏以某种方式忽略目标位置并打开标准 "Documents" 文件夹

已解决,感谢以下代码!


Sub FileSave()
'
' FileSave Macro
' Het actieve document of de actieve sjabloon opslaan
'

   ChangeFileOpenDirectory _
        "F:\Company\Marketing\Voorstellen\Voorstellen\Voorstel\"

        If ActiveDocument.Path = "" Then
        ' If the document has never been saved, the
        ' value of its .Path is an empty string; otherwise
        ' it has the file's path and name.
        With Dialogs(wdDialogFileSaveAs)
            .Name = MakeDocName  ' call the function below
            .Show                ' the suggested name will be in the dialog
        End With
    Else
        ' The document has already been saved with a name
        ' so just save it there.
        ActiveDocument.Save

       End If

End Sub


 Function MakeDocName() As String
    Dim theName As String
         Trim(ActiveDocument.BuiltInDocumentProperties("Title"))
    MakeDocName = theName  ' return the assembled name
End Function

删除 (\)backslash

theName = "F:\Company\Marketing\Voorstellen\Voorstellen\Voorstel\"

theName = "F:\Company\Marketing\Voorstellen\Voorstellen\Voorstel"
                                                           ^'suggested Name = Voorstel

我刚刚删除了你的 MakeDocName 函数的所有 non-operative 部分,这对我来说在 Word 2010 中工作得很好(另请注意标题 属性:

中的大写字母 T
Function MakeDocName() As String
    Dim theName As String
        theName = "C:[=10=]_Projects_temp\" & Trim(ActiveDocument.BuiltInDocumentProperties("Title"))
    MakeDocName = theName  ' return the assembled name
End Function