简体   繁体   English

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

[英]Macro works in Word 2013, but not in 2010

I wanted to create a template for my fellow workers and create a Macro which "Saves As.." to a specific file, and also uses the title to suggest the name. 我想为我的同事创建一个模板,并创建一个“将另存为..”到特定文件的宏,并使用标题来建议名称。

Somehow the Macro ignores the location for the destination and opens the standard "Documents" folder 宏以某种方式忽略目标位置,并打开标准的“文档”文件夹

This is solved, thanks to the following code! 这要靠下面的代码解决!

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

Remove the (\\)backslash 删除(\\)backslash

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

To

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

I just removed all the non-operative part of your MakeDocName function and this worked just fine for me in Word 2010 (also note the capital T in Title property: 我刚刚删除了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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM