none
Bookmarking from beginning to end of document RRS feed

  • Question

  • Hello,

    This may be an interesting question to ask:

    I have been trying to bookmark all bold text, copy and then paste to end of document.

    The cycle starts again until it reaches the end of the document.

    Here is the code snippet for anyone to solve; it may contain errors at runtime.

    Sub BookmarkingBold()
    '
    ' BookmarkingBold Macro
    '
    Dim Txtimes As Long
    Dim BkMark As Bookmark
    Txtimes = 1
    For Txtimes = 1 To 10
        With ActiveDocument.Bookmarks
           
            .DefaultSorting = wdSortByName
            .ShowHidden = True
        End With
        Selection.Copy
        Selection.EndKey Unit:=wdStory
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.HomeKey Unit:=wdStory
        Selection.MoveDown Unit:=wdLine, Count:=4
        Selection.MoveUp Unit:=wdLine, Count:=1
        Selection.MoveLeft Unit:=wdCharacter, Count:=1
        Selection.MoveLeft Unit:=wdCharacter, Count:=5, Extend:=wdExtend
        With ActiveDocument.Bookmarks
            .Add Range:=Selection.Range, Name:="BMkI"
            .DefaultSorting = wdSortByName
            .ShowHidden = True
        End With
        Selection.Copy
        Selection.EndKey Unit:=wdStory
        Selection.TypeText Text:=" "
        Selection.TypeParagraph
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.HomeKey Unit:=wdStory
    Next Txtimes

    End Sub

    With a lot of help from anybody, what I want is to perform the following:

    1. Highlight bold entry

    2. Create a bookmark next to the bold entry.

    3. Copy the bold entry

    4. Move to end of document

    5. Paste the bold entry

    6. Go back up to where last bookmarked entry is located.

    Any solutions are welcome by anyone who knows anything about Microsoft Word.

    JohnDBCTX

    Sunday, March 27, 2016 12:13 AM

Answers

  • If all you want to do is replicate bold text at the end of the document, there is no need for such a convoluted process. For example:

    Sub Demo()
    Application.ScreenUpdating = False
    Dim StrTxt As String, Rng As Range
    With ActiveDocument.Range
      .InsertAfter vbCr
      Set Rng = .Characters.Last
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = ""
        .Replacement.Text = ""
        .Font.Bold = True
        .Format = True
        .Forward = True
        .Wrap = wdFindStop
        .Execute
      End With
      Do While .Find.Found
        StrTxt = StrTxt & .Text
        If Right(.Text, 1) <> vbCr Then StrTxt = StrTxt & .vbCr
        .Collapse wdCollapseEnd
        .Find.Execute
      Loop
      With Rng
        .InsertAfter StrTxt
        .Font.Bold = True
      End With
    End With
    Application.ScreenUpdating = True
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]



    Sunday, March 27, 2016 9:05 AM