View Single Post
 
Old 07-20-2023, 09:48 AM
zelarra821 zelarra821 is offline Windows 10 Office 2021
Novice
 
Join Date: Jul 2023
Posts: 5
zelarra821 is on a distinguished road
Default Use a custom function in Word to count specific characters

Hello. Thank you very much for accepting me.

First of all, this is my first time doing something in VBA for Word, so I don't have much of an idea. Yes, it is true that I have worked with VBA for Excel and Access.

Let me tell you.

I have a Word document in which I have created, using VBA, a function that tells me the number of times certain characters are repeated.

Code:
Function Hecho() As Integer 

Dim iCount As Long 

Dim strSearch As String 

 

strSearch = "**" 

iCount = 0 

 

With ActiveDocument.Content.Find 

    .Text = strSearch 

    .Format = False 

    .Wrap = wdFindStop 

    Do While .Execute 

        iCount = iCount + 1 

    Loop 

End With 

 

Hecho = iCount / 2 

 

End Function
Now, I would like to display the result of that function in the document. I'm looking for information on Google and I can't find anything about it.

Could anyone help me?

Thank you so much.
Reply With Quote