Tutorial for first userform compile error

D

DaveK.

Hello:

I have followed the instructions several times on the tutorial to create a
user form.

I keep getting the same compile error after hiting the execute button.

"Method or data member not found"

I copied the code as shown in the tutorial; and the userform pops up nicely
and I can fill in text in both boxes, but I get the compile error above. I
cannot figure if I have a problem in the template bookmark or the code.

Private Sub CommandButton1_Click()

With ActiveDocument
.Bookmarks ("Text1").Range_
.InsertBefore TextBox1
.Bookmarks ("Text2").Range_
.InsertBefore TextBox2

End With

UserForm1.Hide

End Sub

One thing I noted on the tutorial it uses "TextBox1" and "Textbox2" to
describe making the bookmarks on the template with the []. The quotations
marks are not allowed when entering bookmark names, so my bookmarks are
TextBox1 and Textbox2".

Any clues on how to trouble shoot this error will be appreciated.

Thanks, Dave K.
 
J

Jay Freedman

That's a common error caused in part by retyping the code instead of using
copy/paste. You've missed the fact that the code on the web page has a space
between the word Range and the following underscore in two places. That
space is required (see
http://www.word.mvps.org/FAQs/MacrosVBA/_AtEndOfLine.htm for explanation).

You're correct about the quotation marks -- they aren't allowed in the names
you enter in the Bookmarks dialog, and they aren't part of the actual names
of the bookmarks. However, when you refer to the bookmarks in VBA code, the
quotation marks are required there, so VBA doesn't assume that the words are
variables.

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

DaveK.

Thank you very much. I will give it another go!

Thanks again Jay,
Dave

Jay Freedman said:
That's a common error caused in part by retyping the code instead of using
copy/paste. You've missed the fact that the code on the web page has a space
between the word Range and the following underscore in two places. That
space is required (see
http://www.word.mvps.org/FAQs/MacrosVBA/_AtEndOfLine.htm for explanation).

You're correct about the quotation marks -- they aren't allowed in the names
you enter in the Bookmarks dialog, and they aren't part of the actual names
of the bookmarks. However, when you refer to the bookmarks in VBA code, the
quotation marks are required there, so VBA doesn't assume that the words are
variables.

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

DaveK. said:
Hello:

I have followed the instructions several times on the tutorial to
create a user form.

I keep getting the same compile error after hiting the execute button.

"Method or data member not found"

I copied the code as shown in the tutorial; and the userform pops up
nicely and I can fill in text in both boxes, but I get the compile
error above. I cannot figure if I have a problem in the template
bookmark or the code.

Private Sub CommandButton1_Click()

With ActiveDocument
.Bookmarks ("Text1").Range_
.InsertBefore TextBox1
.Bookmarks ("Text2").Range_
.InsertBefore TextBox2

End With

UserForm1.Hide

End Sub

One thing I noted on the tutorial it uses "TextBox1" and "Textbox2" to
describe making the bookmarks on the template with the []. The
quotations marks are not allowed when entering bookmark names, so my
bookmarks are TextBox1 and Textbox2".

Any clues on how to trouble shoot this error will be appreciated.

Thanks, Dave K.
 

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