UserForm_Initialize problem

P

Patrick C. Simonds

Can anyone tell me why the code below does not insert the text at
Bookmarks("LastName") into TextBox1?

Private Sub UserForm_Initialize()

'Places data in the userform text boxes if it exists on the spreadsheet

If ActiveDocument.Bookmarks.Exists("LastName") Then
TextBox1.Text = ActiveDocument.Bookmarks("LastName").Range.Text
End If

End Sub
 
P

Patrick C. Simonds

Sorry about the typo in the original post. This is in a Word document not a
spreadsheet.
 
H

Helmut Weber

Hi Patrick,

you haven't got an excluding ][ bookmark by any chance?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Greg Maxey

It does here is the bookmark range encompasses the text you want
placed in the the textbox. Are you sure your bookmark spans the text
range?
 
P

Patrick C. Simonds

No I am sure it does not. I added the BookMark, how do I get it to encompass
the text? Do I need to have some sort of BookMark end?
 
J

Jay Freedman

If you're creating the bookmark manually, you must select the text
before you insert the bookmark.

If you're creating the bookmark from inside a macro, see
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm.

One thing that's helpful is to go to Tools > Options > View and check
the box for Bookmarks. The ends of the bookmarks will then appear in
the text as gray square brackets (nonprinting characters).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
B

Bear

In addition to Jay's comment, I also find it helpful to click Insert >
Bookmark, select the bookmark name, then click GoTo. This shows me that the
bookmark exists, and what it contains.

Bear
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top