From: andreas on
Dear Experts:

below macro copies all parantheses at the end of the current document.
To spruce this very handy macro up, I would like a counter integrated,
that tells me via a MsgBox ...
.... how many parenthetical expressions have been copied or in the case
none were found
.... no parentheses found in current document

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub CopyParentheticalExpressions()

Dim str As String
str = ""
ActiveWindow.View.ShowFieldCodes = True

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="\(*\)", MatchWildcards:=True,
Forward:=True, Wrap:=wdFindStop) = True

ActiveWindow.View.ShowFieldCodes = True
str = str & Selection.range.Text & vbCr
Selection.Collapse wdCollapseEnd
Loop
End With
ActiveDocument.range.InsertAfter str

ActiveWindow.View.ShowFieldCodes = False

End Sub
From: Greg Maxey on
Rather than continue to hand you finished code, may I suggest that you show
what you have tried that doesn't work?

"andreas" <andreas.hermle(a)gmx.de> wrote in message
news:a200891d-99ef-4e0b-821d-32f83e378197(a)z4g2000yqa.googlegroups.com...
> Dear Experts:
>
> below macro copies all parantheses at the end of the current document.
> To spruce this very handy macro up, I would like a counter integrated,
> that tells me via a MsgBox ...
> ... how many parenthetical expressions have been copied or in the case
> none were found
> ... no parentheses found in current document
>
> Help is much appreciated. Thank you very much in advance.
>
> Regards, Andreas
>
> Sub CopyParentheticalExpressions()
>
> Dim str As String
> str = ""
> ActiveWindow.View.ShowFieldCodes = True
>
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
> With Selection.Find
> Do While .Execute(findText:="\(*\)", MatchWildcards:=True,
> Forward:=True, Wrap:=wdFindStop) = True
>
> ActiveWindow.View.ShowFieldCodes = True
> str = str & Selection.range.Text & vbCr
> Selection.Collapse wdCollapseEnd
> Loop
> End With
> ActiveDocument.range.InsertAfter str
>
> ActiveWindow.View.ShowFieldCodes = False
>
> End Sub


From: Fumei2 via OfficeKB.com on
I agree. If you need a counter for each iteration, then...add a counter. if
you have problems with making it work, show us the code that is the problem.

Greg Maxey wrote:
>Rather than continue to hand you finished code, may I suggest that you show
>what you have tried that doesn't work?
>
>> Dear Experts:
>>
>[quoted text clipped - 31 lines]
>>
>> End Sub

--
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201004/1

From: andreas on
On Apr 15, 8:27 pm, "Fumei2 via OfficeKB.com" <u53619(a)uwe> wrote:
> I agree.  If you need a counter for each iteration, then...add a counter.  if
> you have problems with making it work, show us the code that is the problem.
>
> Greg Maxey wrote:
> >Rather than continue to hand you finished code, may I suggest that you show
> >what you have tried that doesn't work?
>
> >> Dear Experts:
>
> >[quoted text clipped - 31 lines]
>
> >> End Sub
>
> --
> Gerry
>
> Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/word-programming/201004/1

Hi Greg & Fumei,

thank you very much for your swift response.

I did some more trials and came up with my own solutions. It works.
Thank you for taking your time to look into my matter.

Regards, Andreas

Sub CopyParentheticalExpressions()

Dim str As String
Dim intCounter as integer
str = ""
ActiveWindow.View.ShowFieldCodes = True
intCounter = 0
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="\(*\)", MatchWildcards:=True,
Forward:=True, Wrap:=wdFindStop) = True

ActiveWindow.View.ShowFieldCodes = True
str = str & Selection.range.Text & vbCr
Selection.Collapse wdCollapseEnd
intCounter = intCounter + 1
Loop
End With
if intCounter = 0 then
msgbox "None were found"
Else
msgbox "Number found: " & intcounter
end if
ActiveDocument.range.InsertAfter str

ActiveWindow.View.ShowFieldCodes = False

End Sub