Re: use loop to populate bookmarks or fields
- From: "Doug Robbins - Word MVP" <dkr@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 18 Jul 2006 21:09:49 +0200
If the bookmark is created so that it contains a space so that with the
display of bookmarks turned on it looks like [] rather than |, then if you
use
Bookmarks(i).Range.InsertBefore "the text to be inserted"
the text will be inserted inside the [ ].
--
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
"rogge" <rogge@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:543940ED-14FB-4908-9148-287F0B832E56@xxxxxxxxxxxxxxxx
Thank you Jay... That is helpful, i was hoping to not use the Add method.
"Jay Freedman" wrote:
See http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm. The
technique may have to be tweaked a bit. You can refer to a bookmark with
either a numeric index or its assigned name. Use the index to get the
range,
then save off the bookmark's name to use in the last step.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup
so
all may benefit.
rogge wrote:
is there a method to use docWord.Bookmarks(i).Range.Text or
docWord.FormFields(i).Range.Text without deleting the bookmark or
field? ______________________________________________
Hear Ye!, Hear Ye! I am a bit lazy and do not like to type code. So I
thought, "What if i put the fields in a DAO.Recordset in the same
order that the data would appear in MS Word. Then i could loop
through the bookmarks and fields while using the same code to enter
text. This would be great!"
I am using MS Access to place text into a word document. I have tried
bookmarks and fields, but when "docWord.Bookmarks(i).Range.Text =
rds.Fields(i).Value" then the bookmark or field is deleted causing
the data to be placed into the incorret spot and not completing the
transfer.
I know i can use direct references:
docWord.Bookmarks("nameTo").Range.Text = rds.Fields("nameTo").Value
- or the bookmarks can be numbered sequentially:
docWord.Bookmarks("bkm" & i).Range.Text = rds.Fields(i).Value
- or one can just type the document from scratch,
But as i said earlier i am LAZY and would bery much prefer to use a
loop and not have to worry about properly naming bookmarks to
coincide with field names.
For i = 1 To docWord.Bookmarks.Count
docWord.Bookmarks(i).Range.Text = rds.Fields(i).Value
Next i
________________________________________________
For i = 1 To docWord.FormFields.Count
docWord.FormFields(i).Range.Text = rds.Fields(i).Value
Next i
This code runs, umm, err, 'fine (?)' except that the bookmarks or
fields are re-numbered as the bookmarks and fields are deleted and
this causes data to be placed improperly in the word document. Any
"no", i do not run both of these. I am only using fields or
bookmarks.
Thank you veyr much.
.
- Follow-Ups:
- Re: use loop to populate bookmarks or fields
- From: rogge
- Re: use loop to populate bookmarks or fields
- Prev by Date: Re: Learning VBA
- Next by Date: Make a sentence after a bookmark Bold
- Previous by thread: Re: MS Word: Update in the Author Field Is Not Retained
- Next by thread: Re: use loop to populate bookmarks or fields
- Index(es):
Relevant Pages
|