Results 1 to 1 of 1
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code: cmd_BookmarksFromHeadings()

    I have started loading my cleaned-up Bookmark utilities to Under-The-Hood. Here's the first one. Im pasting the command macro into the message, but the entire code requirements arrive as the text attachment.


    <pre>Sub cmd_BookmarksFromHeadings()
    ' Procedure : cmd_BookmarksFromHeadings
    ' Description: Assign a bookmark to each "heading i" styled paragraph..
    ' Copyright: Chris Greaves Inc.
    ' Inputs: None.
    ' Returns: None.
    ' Assumes: Nothing
    ' Side Effects: Bookmarks may be changed.
    ' Tested: By a call from the user.
    ' Apply this to a manual, can then be used by Customizer.

    ' Set up the document. I think I switch to Normal View for faster processing.
    ' If I switched from Selection to Range I could avoid this.
    ActiveWindow.View.Type = wdNormalView

    ' Obtain the run-time parameters from the INI file.
    Dim intLow As Integer ' Most major heading level; defaults to 'Heading 1"
    intLow = strGp(strcApplication, strcModule,_
    strcBookMarkHeadingLevelLow, strcBookMarkHeadingLevelLowDefault)
    Dim intHigh As Integer ' Most minor hading level; defaults to 'Heading 4"
    intHigh = strGp(strcApplication, strcModule,_
    strcBookMarkHeadingLevelHigh, strcBookMarkHeadingLevelHighDefault)
    ' Number of leading characters to use for the bookmark name stem.
    Dim IntLengthText As Integer
    IntLengthText = strGp(strcApplication, strcModule,_
    strcBookMarkTextLength, strcBookMarkTextLengthDefault)
    Dim strHidden As String ' If "_" then bookmarks will be hidden
    strHidden = strGp(strcApplication, strcModule, _
    strcBookMarkTextHidden, strcBookMarkTextHiddenDefault)

    ' Loop through the document, processing each relevant "Heading i" paragraph.
    Dim intLevel As Integer
    For intLevel = intLow To intHigh
    ' Prepare to Edit,Find each "Heading i" styleed paragraph.
    Selection.HomeKey unit:=wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Heading " & Trim(str(intLevel)))
    With Selection.Find
    .Text = "^?" ' any character
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    ' If we found at least one such "heading i" paragraph,
    ' Prepare to loop for any others at the same level.
    If Selection.Find.Execute Then
    Dim rng As Range
    Set rng = Selection.Range
    Selection.MoveDown unit:=wdParagraph, Count:=1
    While Selection.Find.Execute
    rng.End = Selection.Range.Start - 1
    Call strAddBookmark(rng, intLevel, IntLengthText)
    rng.Start = rng.End + 1
    Selection.MoveDown unit:=wdParagraph, Count:=1
    Wend
    rng.End = ActiveDocument.Range.End ' Do the trailing paragraph of this type
    Call strAddBookmark(rng, intLevel, IntLengthText)
    Else
    End If
    Next intLevel
    End Sub
    </pre>

    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •