Microsoft Office Tutorials and References
In Depth Information
Forms: Formatting Text Input in Form Fields
'Add the increment to the field names, and to¶
'the field names in any calculation¶
'Run through from back to front because¶
'executing the dialog box to force update¶
'of the .Default property recreates the form field¶
For counter = nrFields To 1 Step -1¶
Set ffld = rng.FormFields(counter)¶
ffld.Name = ffld.Name & "_" & CStr(increment)¶
If ffld.TextInput.Valid Then¶
If ffld.TextInput.Type = wdCalculationText Then¶
ChangeCalculationCode ffld, increment, aFieldNames()¶
DoEvents¶
End If¶
End If¶
Next counter¶
doc.Protect Type:=wdAllowOnlyFormFields, noreset:=True,
password:=password¶
rng.FormFields(1).Select¶
End Sub¶
' * * * * *¶
Sub ChangeCalculationCode(ffld As Word.FormField, _¶
nr As Long, aFieldNames() As String)¶
'Variable declaration¶
Dim calculationCode As String¶
Dim counter As Long¶
Dim ffldName As String¶
calculationCode = ffld.TextInput.Default¶
'cycle through the base field names that have been¶
'incremented. If found, add the underscore¶
'increment value to the field name in the calculation¶
For counter = 0 To UBound(aFieldNames) - 1¶
If InStr(calculationCode, aFieldNames(counter)) <> 0 Then¶
ffldName = aFieldNames(counter)¶
calculationCode = Left(calculationCode, _¶
(InStr(calculationCode, ffldName) + Len(ffldName) - 1)) _¶
& "_" & CStr(nr) & Mid(calculationCode, _¶
(InStr(calculationCode, ffldName) + Len(ffldName)))¶
End If¶
Next¶
ffld.TextInput.Default = calculationCode¶
'Select it so that executing the dialog box¶
'updates the changed calculation formula¶
ffld.Select¶
Application.Dialogs(wdDialogFormFieldOptions).Execute¶
Selection.Range.FormFields(1).TextInput.Clear¶
End Sub¶
Wrd
Search JabSto ::




Custom Search