Thanks for your response, Greg;
If you read my response to "sparklynic" you'll see that, by using a
suggestion you posted to another question, I was able to identify and rename
the textbox containing the sought for bookmark. I then programatically
select the textbox; and using the selection.goto method, place the text or
graphic where I need them.
Having said that, I'm wondering if there is some inherent weakenss in the
approach I used, which is:
1. Giving the document user a UserForm with a bunch of comboboxes and text
entry controls that they manipulate to get the selections they want, then;
2. Taking those selections piece by piece--control by control, and using
the I-Beam, placeholder type bookmarks and the selection.goto method,
inserting the bits into the document.
I have to say that it was a little annoying to find that the bookmarks
inside the textboxes were invisible to my program until I set focus on the
textbox. Since the textboxes are the last things that get filled, I haven't
had to try to go back into the main document. Maybe that would be a problem.
I'm not sure.
Anyway, if you think the approach you suggest below would be more robust, I
am interested in learning more about it. Can you suggest some MVP papers or
other sources that discuss the basics of using .range in the way you are
suggesting?
By the way, I've seen oRng used as a variable in other bits of code
examples. What does the 'o' stand for?
One question on the code you sent below: In my usage, sMark is a string
variable that carries the name of a bookmark that marks an insertion point in
the document. "sBoxVal" is another string variable that contains the choice
the user has selected from a UserForm control. sMark and sBoxVal change with
each new bookmark to be filled and get passed to my subroutine "FillMark"
(from my original post) to do the actual insertion. If I understand
correctly, your code would look for a bookmark in the document literally
called "sMark". In my case, should sMark and sBoxVal, having previously been
dimensioned as string variables, be used without the quotes as follows?
Sub Test()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Bookmarks(sMark).Range
oRng.Text = sBoxVal
ActiveDocument.Bookmarks.Add sMark, oRng
End Sub
One other question: If the bookmark I'm trying to access is inside a
textbox, would your code below be able to find it if the textbox does not
have focus?
Thanks again for your help.
Bob
"Greg Maxey" wrote:
> I wouldn't try to use GoTo. Try something like:
>
> Sub Test()
> Dim oRng As Word.Range
> Set oRng = ActiveDocument.Bookmarks("sMark").Range
> oRng.Text = "Your Text"
> ActiveDocument.Bookmarks.Add "sMark", oRng
> End Sub
>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Greg Maxey - Word MVP
>
> My web site http://gregmaxey.mvps.org
> Word MVP web site http://word.mvps.org
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>
> RMac wrote:
> > Using Word 2000.
> >
> > I am building a document that I want to use to generate written
> > prescriptions for medicines. In order to control the exact placement
> > of some text and graphics on the page, I would like to use textboxes.
> > However, when I use the following code to do the insertion, the code
> > can't find the bookmarks that are inside a textbox.
> >
> > In the instance of inserting text (for the final version of code,
> > sBoxVal and sMark are set from controls on a UserForm):
> >
> > Sub Macro3()
> > Dim sBoxVal As String, sMark As String
> >
> > sBoxVal = "SomeDrugName"
> > sMark = "DrugName"
> > Call FillMark(sMark, sBoxVal)
> >
> > End Sub
> >
> > Sub FillMark(sMark As String, sBoxVal As String)
> > 'Go to bookmark and transfer the data.
> > Selection.GoTo What:=wdGoToBookmark, Name:=sMark
> > Selection.Range.Text = sBoxVal
> > End Sub
> >
> > In the instance of inserting a graphic (in this case a .bmp of a
> > signature that will vary depending on what doctor is writing the
> > prescription):
> >
> > Sub Macro2()
> >
> > 'Go to Signature bookmark
> > Selection.GoTo What:=wdGoToBookmark, Name:="Signature"
> > 'Insert Signature
> > Selection.InlineShapes.AddPicture FileName:= _
> > ThisDocument.Path & "\JPM Signature.bmp" _
> > , LinkToFile:=False, SaveWithDocument:=True
> >
> > End Sub
> >
> > Both of these approaches seem to work if I am using bookmarks in the
> > main body of the document. I have discovered through fiddling around
> > that if I click on the desired textbox before running the macro so
> > that it has the focus before the macro runs the insertion works just
> > fine. So, I think it might work if I could figure out how to set the
> > focus on the correct textbox programatically.
> >
> > Thanks in advance
>
>
>