Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jul 2008
    Posts
    36
    Thanks
    4
    Thanked 0 Times in 0 Posts

    macro-multiple copy/paste with format (2002 word)

    Hi !
    This is my code.
    It's making a list of some highligted sentences in a document.
    But it has no format. Like colors...
    What change must do ? With colors and when the color changed, type a paragraph…
    Please see the NOTE-1 and NOTE-2 in the attachment document.
    <hr>
    Sub Highligtedselection()
    Dim hah As String
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
    .Text = ""
    .Format = True
    .Highlight = True
    ReDim b(1000)
    Do While .Execute
    i = i + 1
    hah = Selection.Text
    b(i) = hah
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Loop
    .Execute
    End With
    Selection.EndKey Unit:=wdStory
    Selection.TypeText Text:="RAPOR:"
    For e = 1 To i
    Selection.TypeText Text:=b(e)
    Next
    End Sub
    <hr>
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: macro-multiple copy/paste with format (2002 word)

    Welcome to Woody's Lounge!

    Try the following version of the macro. It stores the highlight colors in the second column of the array, and uses this to restore the colors to the paragraphs at the end.
    <code>
    Sub HighlightedSelection()
    Dim hah As String
    Dim i As Integer
    Dim e As Integer
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
    .Text = ""
    .Format = True
    .Highlight = True
    ReDim b(1 To 1000, 1 To 2)
    Do While .Execute
    i = i + 1
    hah = Selection.Text
    b(i, 1) = hah
    b(i, 2) = Selection.Range.HighlightColorIndex
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Loop
    End With
    Selection.EndKey Unit:=wdStory
    Selection.TypeParagraph
    Selection.TypeText Text:="RAPOR: "
    Selection.TypeParagraph
    For e = 1 To i
    If e > 1 Then
    If Not b(e, 2) = b(e - 1, 2) Then
    Selection.Paragraphs(1).Range.HighlightColorIndex = b(e - 1, 2)
    Selection.TypeParagraph
    End If
    End If
    Selection.TypeText Text:=b(e, 1)
    Next e
    Selection.Paragraphs(1).Range.HighlightColorIndex = b(e - 1, 2)
    End Sub</code>

  3. #3
    Lounger
    Join Date
    Jul 2008
    Posts
    36
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: macro-multiple copy/paste with format (2002 word)

    Many thanks, it works perfectly.
    Regards,
    Yken

Posting Permissions

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