![]() |
|
#1
|
||||
|
||||
![]()
I am trying to write a macro that will count every instance of every letter and number in a page or text file and then return the quantities as a new document or text file that I can print. (See sample jpg below).
For instance, I would want it to count every letter and number in the document and return values such as... A=10 B=4 C=... 9=13 so on and so forth. For asthetics, I would like to create a template document that I put the info into, but I already know how to do that.
__________________
Sean Waiting for a ride in the T.A.R.D.I.S. |
#2
|
||||
|
||||
![]()
Here is some code for you:
Code:
Sub CountLetters() Dim LetterArray(33 To 255) As Long Dim n As Long Dim s As Shape Dim strText As String Dim c As Integer For n = 33 To 255 LetterArray(n) = 0 Next n For Each s In ActivePage.FindShapes(Type:=cdrTextShape) strText = s.Text.Frame.Range.Text For n = 1 To Len(strText) c = Asc(Mid$(strText, n, 1)) If c > 32 And c < 256 Then LetterArray(c) = LetterArray(c) + 1 End If Next n Next s strText = "Letter occurence statistics:" & vbCrLf For n = 33 To 255 If LetterArray(n) > 0 Then strText = strText & Chr$(n) & " = " & LetterArray(n) & vbCrLf End If Next n With CreateDocument .ActiveLayer.CreateParagraphText 0, 0, .ActivePage.SizeWidth, .ActivePage.SizeHeight, strText End With End Sub |
#3
|
||||
|
||||
![]()
Thanks Alex. I got an IM from Shelby and what he told me is true... It is amazing that you can always find a solution with so little code.
Currently, most of my banners are all upper case letters, so I can just disregard the lowercase count. But just in case I might need the option in the future, how do I turn off lower case via code?
__________________
Sean Waiting for a ride in the T.A.R.D.I.S. |
#5
|
||||
|
||||
![]()
O.K. Alex, now, how do I put each value in a specific place on the resulting page? For instance, formating the page so that I can make a 6x6 grid and place the values in each cell.
__________________
Sean Waiting for a ride in the T.A.R.D.I.S. |
#6
|
||||
|
||||
![]()
Any Ideas?
__________________
Sean Waiting for a ride in the T.A.R.D.I.S. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|