Originally Posted by
VanDiZ
Thanks for your quick reply fumei and vary sorry for my delay.
msword VBA's built-in help says:
String Function
Returns a Variant (String) containing a repeating character string of the length specified.
Is it actually returns array of a given string of the given length ???
If so and if it is the problem then, I can replace "String(2, Chr(13))" with the "Chr(13) & Chr(13)" so now the code is as bellow
[vba]Sub Xyz()
Dim Cnt As Long
Dim TSCnt As Long
Dim CSChrCnt As Long
Dim TSChrCnt As Long
Dim TSChrCntTmp As Long
Dim CSEndChrRng1 As Range
Dim CSEndChrRng2 As Range
Dim CSRstChrRng1 As Range
Dim CSRstChrRng2 As Range
TSCnt = ActiveDocument.Sentences.Count
Cnt = 1
Do
CSChrCnt = ActiveDocument.Sentences(Cnt).Characters.Count
TSChrCnt = ActiveDocument.Sentences(Cnt).Characters.Count + TSChrCntTmp
Set CSEndChrRng1 = ActiveDocument.Range(TSChrCnt - 2, TSChrCnt - 1)
Set CSRstChrRng1 = ActiveDocument.Range(TSChrCnt - CSChrCnt, TSChrCnt - 2)
Set CSEndChrRng2 = ActiveDocument.Range(TSChrCnt - 3, TSChrCnt - 1)
Set CSRstChrRng2 = ActiveDocument.Range(TSChrCnt - CSChrCnt, TSChrCnt - 3)
MsgBox _
"CSEndChrRng1 = #" & CSEndChrRng1 & "#" _
& Chr(13) & Chr(13) _
& "CSEndChrRng2 = #" & CSEndChrRng2 & "#" _
& Chr(13) & Chr(13) _
& "CSRstChrRng1 = #" & CSRstChrRng1 & "#" _
& Chr(13) & Chr(13) _
& "CSRstChrRng2 = #" & CSRstChrRng2 & "#" _
& Chr(13) & Chr(13) _
& "TSCnt = #" & TSCnt & "#" _
& Chr(13) _
& "Cnt = #" & Cnt & "#"
TSChrCntTmp = TSChrCnt
Cnt = Cnt + 1
Loop Until TSCnt = Cnt
End Sub[/vba] Now it seems not to show the error, I had tested it with a large document (i.e. =rand(99,200)).
Some other questions, please answer.
#1:> Is it possible to use regular-expressions in the IF statement, Do loops, For loops etc. like the find object?
#2:> How can I add custom icons for macros in the quick access toolbar ??? I am using MSOffice 2010 Professional.
Thanks again fumei for your reply.