Created
June 29, 2024 12:50
-
-
Save theking2/3c211db96c84263cde6b94ac50aa2215 to your computer and use it in GitHub Desktop.
ReplaceInFormFields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace the hashtag with a number in all formfield names. Word does not show these updates immediately