T
Tomas Eklund
Using Word 2003
This is my first time using VBA and I am trying to learn by the help file,
which isn't very helpful.
I have created a .dot template with some text and a simple form with 12
text fields. The form appears when a new document based on the template is
created. The user inputs stuff into the text fields of the form and clicks
the OK button. The script then replaces placeholders in the text with the
values specified by the user.
Something like:
Private Sub ButtonOK_Click()
With ActiveDocument.Content.Find
.ClearFormatting
.Execute FindText:="[Placeholder1]", _
ReplaceWith:=TextBox1.Text, _
MatchCase:=False, _
Wrap:=wdFindContinue, _
Replace:=wdReplaceAll
.Execute FindText:="[Placeholder2]", _
ReplaceWith:=TextBox2.Text, _
MatchCase:=False, _
Wrap:=wdFindContinue, _
Replace:=wdReplaceAll
' And so on...
End With
MyForm.Hide
End Sub
Everything seems to work as I expect it except for one thing: The
placeholders that are within the page header are never replaced. I really
don't understand why. When using Word's built-in Search-and-Replace the
headers are searched through, but not from code. What am I missing here?
This is my first time using VBA and I am trying to learn by the help file,
which isn't very helpful.
I have created a .dot template with some text and a simple form with 12
text fields. The form appears when a new document based on the template is
created. The user inputs stuff into the text fields of the form and clicks
the OK button. The script then replaces placeholders in the text with the
values specified by the user.
Something like:
Private Sub ButtonOK_Click()
With ActiveDocument.Content.Find
.ClearFormatting
.Execute FindText:="[Placeholder1]", _
ReplaceWith:=TextBox1.Text, _
MatchCase:=False, _
Wrap:=wdFindContinue, _
Replace:=wdReplaceAll
.Execute FindText:="[Placeholder2]", _
ReplaceWith:=TextBox2.Text, _
MatchCase:=False, _
Wrap:=wdFindContinue, _
Replace:=wdReplaceAll
' And so on...
End With
MyForm.Hide
End Sub
Everything seems to work as I expect it except for one thing: The
placeholders that are within the page header are never replaced. I really
don't understand why. When using Word's built-in Search-and-Replace the
headers are searched through, but not from code. What am I missing here?