Skip to content

Instantly share code, notes, and snippets.

@theking2
Created June 29, 2024 12:50
Show Gist options
  • Save theking2/3c211db96c84263cde6b94ac50aa2215 to your computer and use it in GitHub Desktop.
Save theking2/3c211db96c84263cde6b94ac50aa2215 to your computer and use it in GitHub Desktop.
ReplaceInFormFields
Private Sub ReplaceInFormFields(Semester)
Dim mergeField As Field
Dim fieldCode As String
' Loop through each merge field
For Each mergeField In ActiveDocument.Fields
If mergeField.Type = wdFieldMergeField Then
' Get the field code text
fieldCode = mergeField.Code.Text
' Check if the field code contains a #
If InStr(fieldCode, "#") > 0 Then
' Replace # with a number (e.g., 1)
fieldCode = Replace(fieldCode, "#", Semester)
' Update the field code text
mergeField.Code.Text = fieldCode
End If
End If
Next mergeField
End Sub
@theking2
Copy link
Author

Replace the hashtag with a number in all formfield names. Word does not show these updates immediately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment