Insert Text after Bookmark

P

Pat-O-Spark

Hi,
I'm trying to insert text (usually the same text) at several places in a
document. I've bookmarked these places but can't get the right syntax.
Here's a snippet of the code I've written to try to put the employee's name
in the middle of a sentence (where the bookmark Emp6 exists):

Sub EmpNme()
Dim PloyNme As String
Dim bmRange As Range

Set bmRange = ActiveDocument.Bookmarks("Emp6")
PloyNme = InputBox("Please enter name of Employee",, , 10000, 7000)
bmRange.InsertAfter (PloyNme)
Selection.GoTo What:=wdGoToBookmark, Name:="Emp6"
End Sub

Thanks in Advance
 
D

Doug Robbins - Word MVP

Use


PloyNme = InputBox("Please enter name of Employee",, , 10000, 7000)
ActiveDocument.Bookmarks("Emp6").Range.InsertAfter PloyNme


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Gordon Bentley-Mix

Doug's solution is probably best if you don't need the "bmRange" Rangbe
object you've tried to create somewhere else in your code - and it appears
that you don't. However, if you do need this Range object elsewhere then you
need to modify your code as follows:

Sub EmpNme()
Dim PloyNme As String
Dim bmRange As Range

Set bmRange = ActiveDocument.Bookmarks("Emp6").Range <--- ***HERE***
PloyNme = InputBox("Please enter name of Employee",, , 10000, 7000)
bmRange.InsertAfter (PloyNme)
Selection.GoTo What:=wdGoToBookmark, Name:="Emp6"
End Sub

Your code failed because although you declared bmRange as a Range, you
didn't actually set it to a Range. ;-D

--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
P

Pat-O-Spark

Thanks Doug and Gordon. Not only did you both answer my question, but I
really appreciate your tutoring on what exactly I did wrong, not just for
this instance. Yipee, I'm up and running...
 

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