Results 1 to 3 of 3

Thread: How to copy a range of text?

  1. #1

    Thread Starter
    Lively Member elmnas's Avatar
    Join Date
    Jul 2009
    Posts
    127

    How to copy a range of text?

    Hello guys

    I wonder how do I copy a block of text not paragrahs
    but from the word"claims"until the next 2 linebreaks?

    here is some code I tested.

    test_rws()
    '
    ' Daniels_rws Makro
    '
    '
    Windows("Wordfile.docx [kompatibilitetsläge]").Activate
    ActiveWindow.ActivePane.VerticalPercentScrolled = 0
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Highlight = True
    With Selection.Find
    .Text = "claims"
    .Font.Name = "Arial"
    .Font.Bold = True

    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindAsk
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With

    End Sub

    thank you in advance.

  2. #2
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: How to copy a range of text?

    I assume you're trying to do this from within Word itself. If so, you're in the wrong forum.

    Try something along these lines:

    Code:
    Sub copyClaim()
        Dim doc As Document
        Dim rng As Range
        Dim strCopy As String
        Dim str As String
        Dim claimStart As Integer
        Dim claimEnd As Integer
        Dim lineBreaks As Integer
        Dim j As Integer
        
        Set doc = ActiveDocument
        Set rng = doc.Content
        str = rng.Text
        
        rng.Find.Execute findtext:="claims"
    
        If rng.Find.Found = True Then
            claimStart = rng.Start
    
                For j = claimStart + 1 To Len(str)
                    If Asc(Mid(str, j, 1)) = 13 Then
                        lineBreaks = lineBreaks + 1
                    End If
                    If lineBreaks = 2 Then
                        claimEnd = j
                        Exit For
                    End If
                Next j
                
                If claimEnd > 0 Then
                    strCopy = Mid(str, claimStart, (claimEnd - claimStart) + 1)
                    MsgBox strCopy
                Else
                    MsgBox "No 2nd line break found"
                End If
        End If
    End Sub

  3. #3

    Thread Starter
    Lively Member elmnas's Avatar
    Join Date
    Jul 2009
    Posts
    127

    Re: How to copy a range of text?

    Hi mate thanks for the answer,
    something is wrong with the code you sent,
    I am not sure what the fault is.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width