1
votes

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

2
are getting any Errors?0m3r
No, nothing seems to happen. Like the entire Macro doesn't start. I updated the trust centerBenga
It works in my Word 2010. I bet the reason is that the hardcoded location at `F:` is causing trouble here.Wiktor Stribiżew
Oke, I'm going to try it in location 'C:', maybe the problem lies in the fact that it is an Microsoft Exchange server location. is there a solution for this?Benga
Omar; I tried it with and without the backslash and also on the 'C:' location. It did not work, most likely because it is done on a Microsoft Exchange server, on the shared location. We do have an Excel 2010 Macro running on it, and that one works just fine.Benga

2 Answers

0
votes

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
0
votes

Remove the (\)backslash

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

To

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