S
sprungli
Hello,
My project uses macrobuttons to display and process portions of text within
a document. Each MACROBUTTON contains a PRIVATE field, whose value (text) is
used by the macro called upon clicking the MACROBUTTON. For example, if
{ MACROBUTTON Some text to find } is the MACROBUTTON,
then the value of its code would be
" PRIVATE Some text to find MACROBUTTON MacroBtnClicked Some text to find
"
where MacroBtnClicked is the name of the macro to call.
When the user clicks the MACROBUTTON, the MacroBtnClicked performs some
processing with the value of the PRIVATE field. At some point I need to find
the text contained within a MACROBUTTON, present the user with the
possibility to edit this text (this happens in a dialog), then save the
changes back to the MACROBUTTON. One possible solution is to find the
MACROBUTTON displaying the text in question, unlink it, then recreate it
with the changed text for both the MACROBUTTON itself and the inner PRIVATE
field, as well. I have been wondering though whether there was a more
elegant (and lasier) way of achieving this. I can change the text of the
MACROBUTTON with something like:
Dim txtToFind As String
txtToFind = "Some text to find"
'switch codes On
ActiveDocument.Fields.ToggleShowCodes
With Selection.Find
.ClearFormatting
.Forward = True
.Wrap = wdFindStop Or wdFindContinue
.Text = txtToFind
.Execute
The line above selects the searched text; it can be easily replaced and,
with Codes Off, the MACROBUTTON displays the new text. The problem is the
PRIVATE field: I can't access it, to change its text too. See the code
below. The value of aField is Empty and the Selection.Fields collection is
of length 0.
'switch codes Off
ActiveDocument.Fields.ToggleShowCodes
privateFieldTxt = " PRIVATE " + txtToFind
Do While Selection.Find.Found
For Each aField In Selection.Fields
If StrComp(aField.Code.Text,
privateFieldTxt, 1) = 0 Then
'set the aField.Code.Text to
the new text here.
End If
Next aField
Loop
End With
Am I on the right track? I am almost sure this can be done; but how to get
to the PRIVATE field?
Thanks in advance for any possible solutions.
My project uses macrobuttons to display and process portions of text within
a document. Each MACROBUTTON contains a PRIVATE field, whose value (text) is
used by the macro called upon clicking the MACROBUTTON. For example, if
{ MACROBUTTON Some text to find } is the MACROBUTTON,
then the value of its code would be
" PRIVATE Some text to find MACROBUTTON MacroBtnClicked Some text to find
"
where MacroBtnClicked is the name of the macro to call.
When the user clicks the MACROBUTTON, the MacroBtnClicked performs some
processing with the value of the PRIVATE field. At some point I need to find
the text contained within a MACROBUTTON, present the user with the
possibility to edit this text (this happens in a dialog), then save the
changes back to the MACROBUTTON. One possible solution is to find the
MACROBUTTON displaying the text in question, unlink it, then recreate it
with the changed text for both the MACROBUTTON itself and the inner PRIVATE
field, as well. I have been wondering though whether there was a more
elegant (and lasier) way of achieving this. I can change the text of the
MACROBUTTON with something like:
Dim txtToFind As String
txtToFind = "Some text to find"
'switch codes On
ActiveDocument.Fields.ToggleShowCodes
With Selection.Find
.ClearFormatting
.Forward = True
.Wrap = wdFindStop Or wdFindContinue
.Text = txtToFind
.Execute
The line above selects the searched text; it can be easily replaced and,
with Codes Off, the MACROBUTTON displays the new text. The problem is the
PRIVATE field: I can't access it, to change its text too. See the code
below. The value of aField is Empty and the Selection.Fields collection is
of length 0.
'switch codes Off
ActiveDocument.Fields.ToggleShowCodes
privateFieldTxt = " PRIVATE " + txtToFind
Do While Selection.Find.Found
For Each aField In Selection.Fields
If StrComp(aField.Code.Text,
privateFieldTxt, 1) = 0 Then
'set the aField.Code.Text to
the new text here.
End If
Next aField
Loop
End With
Am I on the right track? I am almost sure this can be done; but how to get
to the PRIVATE field?
Thanks in advance for any possible solutions.