宏在Word 2013中有效,但在2010年没有

时间:2015-07-09 08:22:19

标签: vba ms-word word-vba word-2010

我想为我的同事创建一个模板并创建一个宏,其中“拯救为......”#34;到特定文件,并使用标题来建议名称。

宏以某种方式忽略目的地的位置并打开标准" 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

2 个答案:

答案 0 :(得分:0)

删除 (\)backslash

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

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

答案 1 :(得分:0)

我刚刚删除了MakeDocName函数的所有非操作部分,这在Word 2010中对我来说效果很好(还要注意Title属性中的大写字母T:

Function MakeDocName() As String
    Dim theName As String
        theName = "C:\00_Projects_temp\" & Trim(ActiveDocument.BuiltInDocumentProperties("Title"))
    MakeDocName = theName  ' return the assembled name
End Function