Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Userforms in Word with VBA 1

Status
Not open for further replies.

Korrel

Technical User
Mar 7, 2003
7
US
I'm trying to create a userform in Word with VBA. I found this example on the net:

Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks("Vornaam").Range_
.InsertBefore TextBox1
.Bookmarks("Achternaam").Range_
.InsertBefore TextBox2
End With

UserForm1.Hide

End Sub


Somehow VBA is not recognizing the range. I want the form to fill in the text from the userform throughout the entire document wherever it finds the bookmarks.

Please advice.

Thanks
 
The proper line breaking should be:

[tt].Bookmarks("Vornaam").Range _
.InsertBefore TextBox1
.Bookmarks("Achternaam").Range _
.InsertBefore TextBox2[/tt]

BTW, UserForm1.Hide will leave form loaded. If you do not want to use it again or have initialization procedure, it is better to unload it instead:
[tt] Unload Me[/tt] (or UserForm1)

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top