Option Explicit
Public fldFF As Word.FormField
Sub FillBM(strBM As String, strText As String)
[COLOR=red]' procedure that dynamically changes the bookmark content
' value is IN the bookmark, not outside it[/color]
Dim r As Range
Set r = ActiveDocument.Bookmarks(strBM).Range
If ActiveDocument.FormFields("date").Result = "" Then Exit Sub
r.Text = strText
ActiveDocument.Bookmarks.Add Name:=strBM, Range:=r
End Sub
Private Function CurrentFF() As Word.FormField
[COLOR=red]' gets the current formfield as an object[/color]
With Selection
If .FormFields.Count = 1 Then
' CheckBox or DropDown
Set CurrentFF = .FormFields(1)
ElseIf .FormFields.Count = 0 And .Bookmarks.Count > 0 Then
Set CurrentFF = ActiveDocument.FormFields _
(.Bookmarks(.Bookmarks.Count).Name)
End If
End With
End Function
Sub myOnExit()
Set fldFF = CurrentFF
With fldFF
If .Type = wdFieldFormTextInput Then
[COLOR=red]' files the BOOKMARK in the header with
' the formfield value[/color]
Call FillBM("h_date", CurrentFF.Result)
End If
[COLOR=red]' makes the value blank[/color]
.Result = ""
End With
If ActiveDocument.FormFields.Shaded = True Then ActiveDocument.FormFields.Shaded = False
If ActiveWindow.View.TableGridlines = True Then ActiveWindow.View.TableGridlines = False
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect ' Password:="aPassword"
Else
End If
[COLOR=red]'delete the "Enter Date Here" text in cell 1[/color]
ActiveDocument.Tables(1).Cell(Row:=1, Column:=1).Range.Select
Selection.Delete Unit:=wdCharacter, Count:=1
[COLOR=red]'Reprotect Document without resetting form fields[/color]
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True ', Password:="aPassword"
End Sub
Sub redNumber()
[COLOR=red]' sub set as the OnExit macro for formfield
' if starting character is "(" make .Result red
' if not, leave as automatic[/color]
Set fldFF = CurrentFF
With fldFF
If .Type = wdFieldFormTextInput Then
If Left(.Result, 1) = "(" Then
.Range.Font.Color = wdColorRed
Else
.Range.Font.Color = wdColorAutomatic
End If
End If
End With
End Sub