Re: use loop to populate bookmarks or fields



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.





.



Relevant Pages

  • Using Excel VBA to control Word (open document)
    ... I have excel VBA code that does a bunch of stuff in Excel, ... determined by the XL VBA code, then save the Word document under a new name. ... bookmarks resets the bookmark count which means that I'm not deleting all ...
    (microsoft.public.excel.programming)
  • Microsoft Word Merge with Bookmarks and Multiple Pages
    ... query to a Word Document that includes ... bunch of Bookmarks that I want to populate from my query ... sTextToUse As String) ...
    (microsoft.public.access.modulesdaovba)
  • RE: Can I extract a XSLT from a Word DOcument?
    ... > We use Bookmarks for the Data and we use Special Bookmarks for Paragraphs ... This will also involve a re-design of the Doc Creation App. ... > how can I for example extract an XSLT from a Word Document? ... to create the XML data in our Doc Creation App and use a Style ...
    (microsoft.public.word.vba.general)
  • Automating Word from Access
    ... It works by opening a Word document containing bookmarks, setting the value of Word bookmarks to those of fields in the Access form, saving the results as a new document and closing the old one unsaved, thus retaining it for future use. ... This doesn't, though, work with bookmarks, so if I've got fields in my query AddressLine1, AddressLine2 and City, and the particular record doesn't have an entry for AddressLine2, the resulting Word document has an unsightly gap between the first line of the address and the city. ...
    (microsoft.public.access.gettingstarted)
  • Re: Hyperlink + Bookmark Doesnt Work
    ... "anchors" within a Word document, ... following the Help procedures step by step. ... Insert/Bookmark to create the bookmarks. ... How did you format the links to work just on click? ...
    (microsoft.public.word.docmanagement)