I have a template with bookmarks. In a vb macro I replace the bookmark with
text. I need to know a good technique for doing this.
1. when I use 'times new roman' which is a variable width font counting
characters in the bookmark & inserting text has its problem
2. Tried to use tabs in the bookmark but they count for one character when
they may replace lots of characters.
So what's a good solution to truncate too long strings of text & keep the
resulting text with the same positions of the bookmark. TIA
------ I suppose showing some of the code might help:
This is what I use to figure the size the bookmark can take:
act_name = Trim(rstProj![activity name]) & " "
With ActiveDocument.Bookmarks("proj_namep1")
If Len(act_name) > (.End - .Start) Then
act_namep1 = Left(act_name, (.End - .Start))
act_namep2 = Mid(act_name, (.End - .Start + 1))
If Left(act_namep2, 1) = Space(1) Then ' we have a good break
already
Else
For I = (.End - .Start) To 10 Step -1
If Mid(act_namep1, I, 1) = Space(1) Then
act_namep2 = Right(act_namep1, Len(act_namep1) - I)
& act_namep2
act_namep1 = Left(act_namep1, I) & Space(10)
GoTo gotsp ' found a space & shifted appropriately
End If
Next I
If Right(act_namep1, 1) <> Space(1) Then
act_namep2 = Right(act_namep1, 1) & act_namep2
act_namep1 = Left(act_namep1, Len(act_namep1) - 1) & "-"
End If
End If
Else
act_namep1 = act_name
act_namep2 = " "
------------And this is how I stuff the text in the bookmark
Public Sub replacebookmarktext(strbkmk As String, strRep As String)
With ActiveDocument.Bookmarks(strbkmk).Range
.Text = Left(strRep & Space(1),
ActiveDocument.Bookmarks(strbkmk).End _
- ActiveDocument.Bookmarks(strbkmk).Start)
.Select
End With
ActiveDocument.Bookmarks.Add strbkmk, Selection.Range
End Sub

Signature
_________________________________
in Christ's matchless name
73 ted & colleen
n6trf kc6rue
Word Heretic - 24 Dec 2004 02:59 GMT
G'day "ted medin" <n6trf@arrl.net>,
SomeRange.Information(Oh yeah baby)
Also, define and apply styles rather than direct formatting.
Steve Hudson - Word Heretic
steve from wordheretic.com (Email replies require payment)
Without prejudice
ted medin reckoned:
>I have a template with bookmarks. In a vb macro I replace the bookmark with
>text. I need to know a good technique for doing this.
[quoted text clipped - 46 lines]
> ActiveDocument.Bookmarks.Add strbkmk, Selection.Range
>End Sub
Alok - 24 Dec 2004 13:55 GMT
You can use DOCVARIABLE to create a field and update it as and when required .
ctrl+F9 > {docvariable "<varname>" "<value>"} in the document
and then do
activedocument.variables.add "<varname>" "<value>"
Hope this helps.
Alok
> I have a template with bookmarks. In a vb macro I replace the bookmark with
> text. I need to know a good technique for doing this.
[quoted text clipped - 46 lines]
> ActiveDocument.Bookmarks.Add strbkmk, Selection.Range
> End Sub
Charles Kenyon - 24 Dec 2004 15:57 GMT
See http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm.

Signature
Charles Kenyon
Word New User FAQ & Web Directory: http://addbalance.com/word
Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide
See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
>I have a template with bookmarks. In a vb macro I replace the bookmark with
> text. I need to know a good technique for doing this.
[quoted text clipped - 47 lines]
> ActiveDocument.Bookmarks.Add strbkmk, Selection.Range
> End Sub