Microsoft Office Tutorials and References
In Depth Information
Setting Hyperlinks on Index Entries
'skip any tab separator for right-aligned page numbers¶
Do While Mid(entry, entryLength, 1) = vbTab¶
entryLength = entryLength - 1¶
Loop¶
'skip any spaces up to the search entry¶
Do While Mid(entry, entryLength, 1) = " "¶
entryLength = entryLength - 1¶
Loop¶
Loop Until Not IsNumeric(Mid(entry, entryLength, 1))¶
'When there are no more numbers left¶
'the search term is what remains¶
ExtractEntryInfo = Left(entry, entryLength)¶
End Function¶
' * * * * *¶
Function DeriveName(doc As Word.Document, _¶
searchTerm As String) As String¶
'Variable declaration¶
Dim counter As Long¶
Dim bookmarkName As String¶
'Continue when error occurs¶
On Error Resume Next¶
'Limit the base bookmark name to 24 characters¶
'this allows up to four digits for the counter¶
'plus four for the identifier¶
For counter = 0 To 24¶
'If the searchTerm is less than this limit, stop¶
If counter = Len(searchTerm) Then Exit For¶
'Loop through the characters in search term¶
bookmarkName = bookmarkName & Mid(searchTerm, _¶
counter + 1, 1)¶
'Make sure the bookmark name doesn't contain any¶
' illegal characters by trying to use the name¶
doc.Bookmarks.Add bookmarkName¶
If Err.Number > 0 Then¶
'If there's an error, drop the illegal character¶
bookmarkName = Left(bookmarkName, _¶
Len(bookmarkName) - 1)¶
Else¶
'delete the test bookmark¶
doc.Bookmarks(bookmarkName).Delete¶
End If¶
Err.Clear¶
Next counter¶
On Error GoTo 0¶
DeriveName = bookmarkIdentifier & bookmarkName¶
End Function¶
Wrd
Search JabSto ::




Custom Search