View Single Post
  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Userinitials not updating automatically

You seem to have changed your requirement. Either you want the field
updating when you open the document, as originally stated, or you don't.
Perhaps you can tell us exactly what the requirement is here? If you simply
want to insert the user initials of the document creator and get them to
stick through thick and thin, then you either need to convert the field to
text or abandon the field and insert the initials with vba.

Sub Macro2()
Dim oFld As Field
Dim sInit as String
sInit = "GM" ' Set required initials
For Each oFld In ActiveDocument.Fields
If oFld.Type = wdFieldUserInitials Then
If oFld.Result sInit Then
oFld.Update
oFld.Unlink
End If
End If
Next

or

Dim sInit As String
sInit = Application.UserInitials
Selection.TypeText sInit

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Deejay wrote:
Thanks. That's fine, but it must also check the value in the field.
This is because it only needs updating the first time it is created.
Once the letter is done, it shouldn't be updated every time it's
opened.

"Helmut Weber" wrote:

Hi Deejay,

e.g.

Sub Test459()
' update all fields of type wdFieldUserInitials
Dim oFld As Field
For Each oFld In ActiveDocument.Fields
If oFld.Type = wdFieldUserInitials Then
oFld.Update
End If
Next
End Sub

Sub Test459b()
' update second field of type wdFieldUserInitials
Dim oFld As Field ' a field
Dim cFld As Collection ' a collection
Set cFld = New Collection
For Each oFld In ActiveDocument.Fields
If oFld.Type = wdFieldUserInitials Then
' add only fields of type wdFieldUserInitials
' to the collection
cFld.Add oFld
End If
Next
cFld(2).Update
End Sub

Still better would be to enclose the fields in question
in bookmarks at the time they are created.

Maybe I'm missing something.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"