Question

I have a Microsoft Word 2010 Template file with several FormFields on it. There are three at the top for Project Name, Project Location, and Project Number. I intend to intercept the FileSave built-in macro and concatenate the values of the three fields mentioned above to suggest a file name in the save-as dialog. My code consists of:

Sub FileSave()

    With Dialogs(wdDialogFileSaveAs)
        .Name = ThisDocument.FormFields("ProjectNumber").Result & _
                ThisDocument.FormFields("ProjectName").Result & _
                ThisDocument.FormFields("ProjectLocation").Result
        .Show
    End With

End Sub

When I fill out the three fields and press ctrl+s, the save-as dialog indeed appears, but the filename is blank. Upon further investigation in the Immediate window, I can refer to these fields, but their Result property always return an empty string. Thus the filename in the dialog appears blank. I can refer to the boolean properties, the Type property, etc. and display that in a MsgBox via the Immediate window, I just can't get it to return anything for Result. Does anyone have an idea of why this might be?

Was it helpful?

Solution

So it looks like the answer to this question ended up being this: I was still working inside a template document, and not a macro-enabled document. For templates, during a macro's run-time, the fields on the document do not contain values. In order for macros to be able to use values entered into FormFields, it has to be a document and not a template. Hope this helps anyone in search of this question being answered.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top