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.
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
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.