Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.



Public Function strAddBookmark(rng As Range, intLevel As Integer, IntLengthText As Integer, Optional strHidden) As String
' Procedure :   strAddBookmark
' Description:  Add a bookmark with a generated identifier.
' Copyright:    Chris Greaves Inc.
' Inputs:       Range to be bookmarked, heading level number, length of heading text to be used, optional HIDDEN flag..
' Returns:      String identifier assigned to this range.
' Assumes:      Nothing
' Side Effects: Bookmarks may be changed.
' Tested:       By the calls below.
    ' Process optional parameters
    ' strHidden: should be character. If "_" then bookmarks will be hidden
    Dim strHide As String
    strHide = "" ' default is "Not hidden".
    If IsMissing(strHidden) Then ' Thanks Geoff Whitfield!
    Else
        If VarType(strHidden) = vbString Then ' Thanks Geoff Whitfield!
            strHide = strHidden ' Could use just LEFT(,1), but why inhibit the user?
        Else
        End If
    End If
    ' Prepare the stem of the fabricated bookmark name.
    Dim strText As String
    strText = strAlphaOnly(Left$(rng.Text, 2 * IntLengthText))
    strText = Left$(strText, IntLengthText)
    ' Fabricate a bookmark.
    Dim strBkMk As String
    strBkMk = strHide ' Initialize the string; if strHidden = "_" Bookmarks will not be visible.
    strBkMk = strBkMk & strcApplication ' This application identifies all its bookmarks.
    strBkMk = strBkMk & "L" ' Tag it as a "L"evel style bookmark
    strBkMk = strBkMk & Trim(str(intLevel)) ' Use the level number (typically 1 through 4)
    strBkMk = strBkMk & "S" & Trim(str(rng.Start)) ' Tag a unique "S"equence mark using the range "S"tart point.
    strBkMk = strBkMk & strText ' Usually the leading alphabetics of the paragraph
    With ActiveDocument.Bookmarks
        .Add Range:=rng, Name:=strBkMk
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
    strAddBookmark = strBkMk
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1

Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.

Public Function strAddBookmark(rng As Range, intLevel As Integer, IntLengthText As Integer, Optional strHidden) As String
' Procedure :   strAddBookmark
' Description:  Add a bookmark with a generated identifier.
' Copyright:    Chris Greaves Inc.
' Inputs:       Range to be bookmarked, heading level number, length of heading text to be used, optional HIDDEN flag..
' Returns:      String identifier assigned to this range.
' Assumes:      Nothing
' Side Effects: Bookmarks may be changed.
' Tested:       By the calls below.
    ' Process optional parameters
    ' strHidden: should be character. If "_" then bookmarks will be hidden
    Dim strHide As String
    strHide = "" ' default is "Not hidden".
    If IsMissing(strHidden) Then ' Thanks Geoff Whitfield!
    Else
        If VarType(strHidden) = vbString Then ' Thanks Geoff Whitfield!
            strHide = strHidden ' Could use just LEFT(,1), but why inhibit the user?
        Else
        End If
    End If
    ' Prepare the stem of the fabricated bookmark name.
    Dim strText As String
    strText = strAlphaOnly(Left$(rng.Text, 2 * IntLengthText))
    strText = Left$(strText, IntLengthText)
    ' Fabricate a bookmark.
    Dim strBkMk As String
    strBkMk = strHide ' Initialize the string; if strHidden = "_" Bookmarks will not be visible.
    strBkMk = strBkMk & strcApplication ' This application identifies all its bookmarks.
    strBkMk = strBkMk & "L" ' Tag it as a "L"evel style bookmark
    strBkMk = strBkMk & Trim(str(intLevel)) ' Use the level number (typically 1 through 4)
    strBkMk = strBkMk & "S" & Trim(str(rng.Start)) ' Tag a unique "S"equence mark using the range "S"tart point.
    strBkMk = strBkMk & strText ' Usually the leading alphabetics of the paragraph
    With ActiveDocument.Bookmarks
        .Add Range:=rng, Name:=strBkMk
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
    strAddBookmark = strBkMk
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1