Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

Using bookmarks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TF - 31 Oct 2006 18:31 GMT
Hello,
Can I insert severals lines (with LF), using only one bookmark ?
How can I do it in VBA ?
Thanks
Jay Freedman - 31 Oct 2006 19:03 GMT
Yes, just embed the line feed in the string that you assign to the bookmark.
There are two kinds of "line feed":

- a paragraph mark (Enter key), represented in VBA by the constant vbCr
- a manual line break (Shift+Enter key), represented in VBA by the constant
vbVerticalTab

For an example, make a document and insert a bookmark named "bk1". Then run
this code. Look at the result with nonprinting characters turned on (press
Ctrl+* or click the ¶ button).

Sub MultilineInsert()
   Dim textToInsert As String
   Dim bkmkRng As Range

   On Error GoTo ErrHdl
   Set bkmkRng = ActiveDocument.Bookmarks("bk1").Range

   textToInsert = "Line 1" & vbCr & "Line 2" & vbVerticalTab & "Line 3"

   bkmkRng.Text = textToInsert
   ActiveDocument.Bookmarks.Add Name:="bk1", Range:=bkmkRng

   Exit Sub

ErrHdl:
   MsgBox Err.Description
End Sub

The part about Bookmarks.Add comes from the article
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm.

Signature

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.

> Hello,
> Can I insert severals lines (with LF), using only one bookmark ?
> How can I do it in VBA ?
> Thanks
TF - 01 Nov 2006 10:58 GMT
Thanks,
I work with MS Access,
I have to generate a Word document (using a Word model DOT).
For every insertion position I need 2 bookmarks.
When I insert several lines, I use the first one,
When I read at bookmar has several lines, I read between these 2 bookmarks.
So, I can insert severals lines and read them between 2 bookmarks.

This method works correctly for writing several lines with (the lines come
from a MS Access TextBox). I verify the Word document, it is OK.
My problem, is in reading this Word document :
I extract these lines from Word document (between the 2 bookmarks), lines
are in a uniq line without (vbcr or vbverticatab) ??

But when I read the CRLF is omitted
> Yes, just embed the line feed in the string that you assign to the bookmark.
> There are two kinds of "line feed":
[quoted text clipped - 32 lines]
> > How can I do it in VBA ?
> > Thanks
Jay Freedman - 01 Nov 2006 15:17 GMT
This will go easier if you use only one bookmark, which encloses the text
you insert or read.

As explained in http://word.mvps.org/faqs/macrosvba/WorkWithBookmarks.htm,
you can work with bookmarks that are just placeholders but don't contain any
text, or you can work with bookmarks that enclose text. (They aren't really
different; it's only the way you use them that's different.)

The example I showed in my previous post, which is similar to the code at
the bottom of that article, inserts the text in an enclosing bookmark. To
read the text that's enclosed by that one bookmark, all you need is a line
like

  myText = ActiveDocument.Bookmarks("bk1").Range.Text

If your code to read the document expects the text to be between two
placeholder bookmarks, then you won't get the correct results. Pick one
method or the other, and use it for both writing and reading.

Signature

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.

> Thanks,
> I work with MS Access,
[quoted text clipped - 57 lines]
>>> How can I do it in VBA ?
>>> Thanks
TF - 02 Nov 2006 13:02 GMT
Thank for helping me,
Ok, I use one bookmark for inserting and the same for reading a field.
as explain at your site :
(http://word.mvps.org/faqs/macrosvba/WorkWithBookmarks.htm)
It's very good site.

I've changed my program, I do this command :
==> Set RG = ActiveDocument.Bookmarks("bk1").Range
==> Frm!field1 = RG.Text
yours is more suitable :
frm!field = ActiveDocument.Bookmarks("bk1").Range.Text

But I have the major problem :
if I write several lines in my bookmark, I see these line in the Word
document.
In reading mode from the same Word document, the Access textbox concatenate
all lines in one line ?
if i have wrote :
aaaaaa
bbbbb
ccccc
in reading mode, i have an uniq line:
aaaaaabbbbbccccc
Thanks.
.

> This will go easier if you use only one bookmark, which encloses the text
> you insert or read.
[quoted text clipped - 76 lines]
> >>> How can I do it in VBA ?
> >>> Thanks
Jay Freedman - 02 Nov 2006 17:45 GMT
I don't know anything about Access automation or how it reads from Word
files. I assume that the paragraph mark in Word is available to the Access
code, but it's being suppressed for some reason. You probably need to put
the bookmark's text into a string variable in the Access code, and replace
the paragraph marks (character value ASCII 13) with some other character
that will separate the displayed text into multiple lines. Then you can
assign that revised string to the form field.

If you can't figure that out on your own, you'll have to get help from
someone else.

Signature

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.

> Thank for helping me,
> Ok, I use one bookmark for inserting and the same for reading a field.
[quoted text clipped - 110 lines]
>>>>> How can I do it in VBA ?
>>>>> Thanks
TF - 03 Nov 2006 11:56 GMT
Hello,
In Access I use VBA codes, T tried to convert vbcr to vbcrlf, to
vbverticaltab, the proble is still the same.
Thanks for helps.
I'll try with Access news !

> I don't know anything about Access automation or how it reads from Word
> files. I assume that the paragraph mark in Word is available to the Access
[quoted text clipped - 121 lines]
> >>>>> How can I do it in VBA ?
> >>>>> Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.