Replace Bookmark Text with UserForms

W

Wendy D

(FYI - I posted this on the beginners, general, and userforms boards.)

I have created a template where I created a userform with 2 "fields"
(ProjectName and TaskName). Each field corresponds w/a bookmark. I'm using
REF commands to link/repeat the bookmarks in the footer of the report. It is
all working well except that the data that is input through the userform is
getting added to the (default) bookmark text instead of replacing it. I
found a MVP document that gives me a general idea of what I need to do (set a
bookmark range variable) {MVP Doc: Inserting text at a bookmark without
deleting the bookmark}. It includes a subroutine when using a
macros/userform, but I'm not sure where to put it. Can anyone help me with
this???

THANK YOU!
Wendy

Now, template bookmarks look like: [ProjectName] and [TaskName]. If I
input a 1 (for project name) and a 2 (for task name) in the userform when I
open a new document, the bookmark data changes to: [1ProjectName] and
[2TaskName]. I need it to change to [1] and [2] (but keep the bookmarks).

My VBA code has:

AUTONEW MODULE
Sub AutoNew()
'
' AutoNew Macro
' Macro created 8/16/2005 by wdaniels
'
UserForm1.Show

End Sub

USERFORM - Commandbutton1
Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks("ProjectName").Range _
.InsertBefore TextBox1
.Bookmarks("TaskName").Range _
.InsertBefore TextBox2
End With

UserForm1.Hide

End Sub
 
J

Jean-Guy Marcil

Wendy D was telling us:
Wendy D nous racontait que :
(FYI - I posted this on the beginners, general, and userforms boards.)

Thanks for letting us know that you have multiposted your message (Same
message in diffrent groups at the same time). You can crosspost if it is
absolutely necessary (in this case it isn't, the userform board would have
been enough). If you do, include all the group names in the To: field when
creating the message. For example:
"To: microsoft.public.word.vba.beginners,
microsoft.public.word.vba.general, microsoft.public.word.vba.userforms"

This way all replies will appear at the same time in all groups and
everybody will see all the answers regardless of the group they are viewing
your post from. This will tell someone that it has already been answered
(They will see the answers in the thread), thus avoiding wasting their time
answering to a post that has already been replied to. Multiposting (has you
have doe) is not good NG etiquette, and it forces people to track down your
other messages to reply to them as well, whereas crosspoting is more
acceptable, although not usually necessary.
I have created a template where I created a userform with 2 "fields"
(ProjectName and TaskName). Each field corresponds w/a bookmark.
I'm using REF commands to link/repeat the bookmarks in the footer of
the report. It is all working well except that the data that is
input through the userform is getting added to the (default) bookmark
text instead of replacing it. I found a MVP document that gives me a
general idea of what I need to do (set a bookmark range variable)
{MVP Doc: Inserting text at a bookmark without deleting the
bookmark}. It includes a subroutine when using a macros/userform,
but I'm not sure where to put it. Can anyone help me with this???

Put the MVP code in the click event of the button that will carry out the
process from the userform.
USERFORM - Commandbutton1
Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks("ProjectName").Range _
.InsertBefore TextBox1
.Bookmarks("TaskName").Range _
.InsertBefore TextBox2
End With

UserForm1.Hide

End Sub

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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