Counter for macro

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

Open in new window

Andreas HermleTeam leaderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
Give this a try:
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

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andreas HermleTeam leaderAuthor Commented:
Hi mbizup,

thank you very much for your professional help. It works! Regards, Andreas
0
mbizupCommented:
> thank you very much

You are very welcome :)

I'm glad this worked for you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.