UserForms: CommandButton Help

W

Wendy D

Hi. I'm trying to create a userform within/for a template. I've followed
the instructions here:
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm.

Everything seems to have worked right except for step #10. When I create a
new document off the template, I do get the user form. But when I hit the
"CommandButton1" (or if I try and compile while in the "viewcode" of the
command button), I get a COMPILE ERROR: Method or Data Member Not Found.
When I OK the message, it highlights the .Range portion of the code.

I think I have everything the same as instructed, so I'm not sure what's
wrong. Within ViewCode of CommandButton1 (UserForm1) I have:

Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks("ProjectName").Range_
.InsertBefore TextBox1
.Bookmarks("TaskName").Range_
.InsertBefore TextBox2
End With

UserForm1.Hide

End Sub

Anyone know how to fix me?

Thanks!
Wendy
 
J

Jay Freedman

Wendy said:
Hi. I'm trying to create a userform within/for a template. I've
followed the instructions here:
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm.

Everything seems to have worked right except for step #10. When I
create a new document off the template, I do get the user form. But
when I hit the "CommandButton1" (or if I try and compile while in the
"viewcode" of the command button), I get a COMPILE ERROR: Method or
Data Member Not Found. When I OK the message, it highlights the
.Range portion of the code.

I think I have everything the same as instructed, so I'm not sure
what's wrong. Within ViewCode of CommandButton1 (UserForm1) I have:

Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks("ProjectName").Range_
.InsertBefore TextBox1
.Bookmarks("TaskName").Range_
.InsertBefore TextBox2
End With

UserForm1.Hide

End Sub

Anyone know how to fix me?

Thanks!
Wendy

Hi Wendy,

Insert a space character before the underscore in each of the two Range
expressions. See

What are the underscores _ at the end of lines of code there for?
http://word.mvps.org/FAQs/MacrosVBA/_AtEndOfLine.htm
 
S

Suzanne S. Barnhill

You might get a faster and more authoritative answer if you post in the
microsoft.public.word.vba.userforms newsgroup.
 

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