Search code examples
vbams-wordword-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


Solution

  • 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:

    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