"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
>
>
>