R
Ruth
I'm trying to create a userform in connection with a template with
lots of bookmarks. The userform collects some text fields and then
fills them into the bookmarks.
I also have a combobox with several names. Once a name is selected, I
want the code to jump to various bookmarks in the template and fill in
text. It worked fine when I only had one name, but as soon as I add a
second name to the code, when I run the template, it is filled with
the info for BOTH names!
here is the code
Private Sub CommandButton1_Click()
With ActiveDocument
..Bookmarks("Address").Range.Text = txtaddress
..Bookmarks("RE1").Range.Text = txtre
..Bookmarks("Typist").Range.Text = txtInitials
..Bookmarks("Salutation").Range.Text = txtSal
..Bookmarks("Closing").Range.Text = cboClose.Value
..Bookmarks("Delivery").Range.Text = cboDelivery.Value
End With
If cboName.Value = "Jane Doe" Then GoTo Doe Else
If cboName.Value = "John Smith" Then GoTo Smith
Doe:
With ActiveDocument
.Bookmarks("Attorney").Range.Text = cboName
.Bookmarks("Member").Range.Text = ""
Selection.Font.Size = 8
Selection.Font.Italic = wdToggle
.Bookmarks("email").Range.Text = "(e-mail address removed)"
Selection.Font.Italic = wdToggle
Selection.Font.Size = 12
.Bookmarks("Attorney2").Range.Text = cboName
.Bookmarks("Initials").Range.Text = "JD"
Selection.GoTo What:=wdGoToBookmark, Name:="BeginHere"
End With
Smith:
With ActiveDocument
.Bookmarks("Attorney").Range.Text = cboName
.Bookmarks("Member").Range.Text = ""
Selection.Font.Size = 8
Selection.Font.Italic = wdToggle
.Bookmarks("email").Range.Text = "(e-mail address removed)"
Selection.Font.Italic = wdToggle
Selection.Font.Size = 12
.Bookmarks("Attorney2").Range.Text = cboName
.Bookmarks("Initials").Range.Text = "JS"
Selection.GoTo What:=wdGoToBookmark, Name:="BeginHere"
End With
UserForm1.Hide
End Sub
lots of bookmarks. The userform collects some text fields and then
fills them into the bookmarks.
I also have a combobox with several names. Once a name is selected, I
want the code to jump to various bookmarks in the template and fill in
text. It worked fine when I only had one name, but as soon as I add a
second name to the code, when I run the template, it is filled with
the info for BOTH names!
here is the code
Private Sub CommandButton1_Click()
With ActiveDocument
..Bookmarks("Address").Range.Text = txtaddress
..Bookmarks("RE1").Range.Text = txtre
..Bookmarks("Typist").Range.Text = txtInitials
..Bookmarks("Salutation").Range.Text = txtSal
..Bookmarks("Closing").Range.Text = cboClose.Value
..Bookmarks("Delivery").Range.Text = cboDelivery.Value
End With
If cboName.Value = "Jane Doe" Then GoTo Doe Else
If cboName.Value = "John Smith" Then GoTo Smith
Doe:
With ActiveDocument
.Bookmarks("Attorney").Range.Text = cboName
.Bookmarks("Member").Range.Text = ""
Selection.Font.Size = 8
Selection.Font.Italic = wdToggle
.Bookmarks("email").Range.Text = "(e-mail address removed)"
Selection.Font.Italic = wdToggle
Selection.Font.Size = 12
.Bookmarks("Attorney2").Range.Text = cboName
.Bookmarks("Initials").Range.Text = "JD"
Selection.GoTo What:=wdGoToBookmark, Name:="BeginHere"
End With
Smith:
With ActiveDocument
.Bookmarks("Attorney").Range.Text = cboName
.Bookmarks("Member").Range.Text = ""
Selection.Font.Size = 8
Selection.Font.Italic = wdToggle
.Bookmarks("email").Range.Text = "(e-mail address removed)"
Selection.Font.Italic = wdToggle
Selection.Font.Size = 12
.Bookmarks("Attorney2").Range.Text = cboName
.Bookmarks("Initials").Range.Text = "JS"
Selection.GoTo What:=wdGoToBookmark, Name:="BeginHere"
End With
UserForm1.Hide
End Sub