View Single Post
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 264
Default Populate file properties from text fields in document

Set the following macro to run on exit from text formfields Text1 and
Text2


Sub OnExitTF()
Dim oFF As FormFields
Set oFF = ActiveDocument.FormFields
Dim pStr As String
If Selection.FormFields.Count = 1 Then
pStr = Selection.FormFields(1).Name
ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count
0 Then
pStr = Selection.Bookmarks(Selection.Bookmarks.Count).Nam e
End If
Select Case pStr
Case "Text1"
ActiveDocument.BuiltInDocumentProperties("Title"). Value =
oFF("Text1").Result
Case "Text2"
ActiveDocument.BuiltInDocumentProperties("Subject" ).Value =
oFF("Text2").Result
End Select
End Sub

On Apr 24, 6:44 am, Embobz wrote:
I am trying to get the Subject and Title from the file properties of a
document to be set automatically from specified text fields in the
body of the document. I can quite easily go the other way by typing
text into the title and subject fields in the properties dialog box,
and inserting relevant fields into the document, but that's not what I
want. Is there a way to do it using macros, or can I insert a field
so that when a user edits the field, it will automatically update the
file properties. Is this even possible? I consider myself an
'advanced user' of Word, but with some limited experience in coding,
just so you'll know where to pitch any answer to me. Thanks.