T
ted medin
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
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