Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.tables
|
|||
|
|||
wordcount macro for tables and brackets
Hello
I have a macro which excludes words inside tables and brackets from the general word count in a document. The problem is the macro is not in the right format (the writing appears red in Visual Basic Editor). Does anyone know the right format for the macro or how I can get it to be right? Any help is greatly appreciated, many thanks. The macro is as follows: Public Sub StatisticsExcludingTables() Dim tblItem As Word.Table Dim rngReplace As Word.Range Dim rngFound As Word.Range Dim lngCharacters As Long Dim lngCharactersWithSpaces As Long Dim lngFarEastCharacters As Long Dim lngLines As Long Dim lngPages As Long Dim lngParagraphs As Long Dim lngWords As Long ' Get the totals for the document With ActiveDocument lngCharacters = ..ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = _ ..ComputeStatistics(wdStatisticCharactersWithSpace s) lngFarEastCharacters = _ ..ComputeStatistics(wdStatisticFarEastCharacters) lngLines = ..ComputeStatistics(wdStatisticLines) lngPages = ..ComputeStatistics(wdStatisticPages) lngParagraphs = ..ComputeStatistics(wdStatisticParagraphs) lngWords = ..ComputeStatistics(wdStatisticWords) End With ' Subtract out the table statistics For Each tblItem In ActiveDocument.Tables With tblItem.Range lngCharacters = lngCharacters - _ .ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = lngCharactersWithSpaces - _ ..ComputeStatistics(wdStatisticCharactersWithSpace s) lngFarEastCharacters = lngFarEastCharacters - _ .ComputeStatistics(wdStatisticFarEastCharacters) lngLines = lngLines - .ComputeStatistics(wdStatisticLines) lngPages = lngPages - .ComputeStatistics(wdStatisticPages) lngParagraphs = lngParagraphs - _ .ComputeStatistics(wdStatisticParagraphs) lngWords = lngWords - ..ComputeStatistics(wdStatisticWords) End With Next ' Search document for parenthesised words Set rngReplace = ActiveDocument.Content With rngReplace.Find .ClearFormatting .Replacement.ClearFormatting .Text = "\(*\)" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False ..MatchSoundsLike = False .MatchWildcards = True ' Find all occurrences in the document Do While .Execute ' Exclude statistics the words in parenthesis Set rngFound = rngReplace.Duplicate With rngFound lngCharacters = lngCharacters - _ .ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = lngCharactersWithSpaces - _ ..ComputeStatistics(wdStatisticCharactersWithSpace s) lngFarEastCharacters = lngFarEastCharacters - _ .ComputeStatistics(wdStatisticFarEastCharacters) lngWords = lngWords - .ComputeStatistics(wdStatisticWords) End With ' Setup range to continue the search after ' the text that we just found rngReplace.Collapse wdCollapseEnd Loop End With MsgBox "Pages: " & lngPages & vbCr & _ "Paragraphs: " & lngParagraphs & vbCr & _ "Lines: " & lngLines & vbCr & _ "Words: " & lngWords & vbCr & _ "Characters: " & lngCharacters & vbCr & _ "Characters with spaces: " & lngCharactersWithSpaces & vbCr & _ "Far east Characters: " & lngFarEastCharacters End Sub |
#2
Posted to microsoft.public.word.tables
|
|||
|
|||
wordcount macro for tables and brackets
It should be:
Public Sub StatisticsExcludingTables() Dim tblItem As Word.Table Dim rngReplace As Word.Range Dim rngFound As Word.Range Dim lngCharacters As Long Dim lngCharactersWithSpaces As Long Dim lngFarEastCharacters As Long Dim lngLines As Long Dim lngPages As Long Dim lngParagraphs As Long Dim lngWords As Long ' Get the totals for the document With ActiveDocument lngCharacters = .ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = ..ComputeStatistics(wdStatisticCharactersWithSpace s) lngFarEastCharacters = .ComputeStatistics(wdStatisticFarEastCharacters) lngLines = .ComputeStatistics(wdStatisticLines) lngPages = .ComputeStatistics(wdStatisticPages) lngParagraphs = .ComputeStatistics(wdStatisticParagraphs) lngWords = .ComputeStatistics(wdStatisticWords) End With ' Subtract out the table statistics For Each tblItem In ActiveDocument.Tables With tblItem.Range lngCharacters = lngCharacters - ..ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = lngCharactersWithSpaces - _ ..ComputeStatistics(wdStatisticCharactersWithSpace s) lngFarEastCharacters = lngFarEastCharacters - _ ..ComputeStatistics(wdStatisticFarEastCharacters) lngLines = lngLines - .ComputeStatistics(wdStatisticLines) lngPages = lngPages - .ComputeStatistics(wdStatisticPages) lngParagraphs = lngParagraphs - ..ComputeStatistics(wdStatisticParagraphs) lngWords = lngWords - .ComputeStatistics(wdStatisticWords) End With Next ' Search document for parenthesised words Set rngReplace = ActiveDocument.Content With rngReplace.Find .ClearFormatting .Replacement.ClearFormatting .Text = "\(*\)" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True ' Find all occurrences in the document Do While .Execute ' Exclude statistics the words in parenthesis Set rngFound = rngReplace.Duplicate With rngFound lngCharacters = lngCharacters - ..ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = lngCharactersWithSpaces - _ ..ComputeStatistics(wdStatisticCharactersWithSpace s) lngFarEastCharacters = lngFarEastCharacters - _ ..ComputeStatistics(wdStatisticFarEastCharacters) lngWords = lngWords - .ComputeStatistics(wdStatisticWords) End With ' Setup range to continue the search after ' the text that we just found rngReplace.Collapse wdCollapseEnd Loop End With MsgBox "Pages: " & lngPages & vbCr & _ "Paragraphs: " & lngParagraphs & vbCr & _ "Lines: " & lngLines & vbCr & _ "Words: " & lngWords & vbCr & _ "Characters: " & lngCharacters & vbCr & _ "Characters with spaces: " & lngCharactersWithSpaces & vbCr & _ "Far east Characters: " & lngFarEastCharacters End Sub Even then, you will need to watch out for line breaks that are inserted by the email program. -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "Nikeel" wrote in message ... Hello I have a macro which excludes words inside tables and brackets from the general word count in a document. The problem is the macro is not in the right format (the writing appears red in Visual Basic Editor). Does anyone know the right format for the macro or how I can get it to be right? Any help is greatly appreciated, many thanks. The macro is as follows: Public Sub StatisticsExcludingTables() Dim tblItem As Word.Table Dim rngReplace As Word.Range Dim rngFound As Word.Range Dim lngCharacters As Long Dim lngCharactersWithSpaces As Long Dim lngFarEastCharacters As Long Dim lngLines As Long Dim lngPages As Long Dim lngParagraphs As Long Dim lngWords As Long ' Get the totals for the document With ActiveDocument lngCharacters = .ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = _ .ComputeStatistics(wdStatisticCharactersWithSpaces ) lngFarEastCharacters = _ .ComputeStatistics(wdStatisticFarEastCharacters) lngLines = .ComputeStatistics(wdStatisticLines) lngPages = .ComputeStatistics(wdStatisticPages) lngParagraphs = .ComputeStatistics(wdStatisticParagraphs) lngWords = .ComputeStatistics(wdStatisticWords) End With ' Subtract out the table statistics For Each tblItem In ActiveDocument.Tables With tblItem.Range lngCharacters = lngCharacters - _ .ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = lngCharactersWithSpaces - _ .ComputeStatistics(wdStatisticCharactersWithSpaces ) lngFarEastCharacters = lngFarEastCharacters - _ .ComputeStatistics(wdStatisticFarEastCharacters) lngLines = lngLines - .ComputeStatistics(wdStatisticLines) lngPages = lngPages - .ComputeStatistics(wdStatisticPages) lngParagraphs = lngParagraphs - _ .ComputeStatistics(wdStatisticParagraphs) lngWords = lngWords - .ComputeStatistics(wdStatisticWords) End With Next ' Search document for parenthesised words Set rngReplace = ActiveDocument.Content With rngReplace.Find .ClearFormatting .Replacement.ClearFormatting .Text = "\(*\)" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True ' Find all occurrences in the document Do While .Execute ' Exclude statistics the words in parenthesis Set rngFound = rngReplace.Duplicate With rngFound lngCharacters = lngCharacters - _ .ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = lngCharactersWithSpaces - _ .ComputeStatistics(wdStatisticCharactersWithSpaces ) lngFarEastCharacters = lngFarEastCharacters - _ .ComputeStatistics(wdStatisticFarEastCharacters) lngWords = lngWords - .ComputeStatistics(wdStatisticWords) End With ' Setup range to continue the search after ' the text that we just found rngReplace.Collapse wdCollapseEnd Loop End With MsgBox "Pages: " & lngPages & vbCr & _ "Paragraphs: " & lngParagraphs & vbCr & _ "Lines: " & lngLines & vbCr & _ "Words: " & lngWords & vbCr & _ "Characters: " & lngCharacters & vbCr & _ "Characters with spaces: " & lngCharactersWithSpaces & vbCr & _ "Far east Characters: " & lngFarEastCharacters End Sub |
#3
Posted to microsoft.public.word.tables
|
|||
|
|||
wordcount macro for tables and brackets
Hi Doug
Thank you so much for your help. You've been a great help. Many thanks. Nik "Doug Robbins - Word MVP" wrote: It should be: Public Sub StatisticsExcludingTables() Dim tblItem As Word.Table Dim rngReplace As Word.Range Dim rngFound As Word.Range Dim lngCharacters As Long Dim lngCharactersWithSpaces As Long Dim lngFarEastCharacters As Long Dim lngLines As Long Dim lngPages As Long Dim lngParagraphs As Long Dim lngWords As Long ' Get the totals for the document With ActiveDocument lngCharacters = .ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = ..ComputeStatistics(wdStatisticCharactersWithSpace s) lngFarEastCharacters = .ComputeStatistics(wdStatisticFarEastCharacters) lngLines = .ComputeStatistics(wdStatisticLines) lngPages = .ComputeStatistics(wdStatisticPages) lngParagraphs = .ComputeStatistics(wdStatisticParagraphs) lngWords = .ComputeStatistics(wdStatisticWords) End With ' Subtract out the table statistics For Each tblItem In ActiveDocument.Tables With tblItem.Range lngCharacters = lngCharacters - ..ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = lngCharactersWithSpaces - _ ..ComputeStatistics(wdStatisticCharactersWithSpace s) lngFarEastCharacters = lngFarEastCharacters - _ ..ComputeStatistics(wdStatisticFarEastCharacters) lngLines = lngLines - .ComputeStatistics(wdStatisticLines) lngPages = lngPages - .ComputeStatistics(wdStatisticPages) lngParagraphs = lngParagraphs - ..ComputeStatistics(wdStatisticParagraphs) lngWords = lngWords - .ComputeStatistics(wdStatisticWords) End With Next ' Search document for parenthesised words Set rngReplace = ActiveDocument.Content With rngReplace.Find .ClearFormatting .Replacement.ClearFormatting .Text = "\(*\)" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True ' Find all occurrences in the document Do While .Execute ' Exclude statistics the words in parenthesis Set rngFound = rngReplace.Duplicate With rngFound lngCharacters = lngCharacters - ..ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = lngCharactersWithSpaces - _ ..ComputeStatistics(wdStatisticCharactersWithSpace s) lngFarEastCharacters = lngFarEastCharacters - _ ..ComputeStatistics(wdStatisticFarEastCharacters) lngWords = lngWords - .ComputeStatistics(wdStatisticWords) End With ' Setup range to continue the search after ' the text that we just found rngReplace.Collapse wdCollapseEnd Loop End With MsgBox "Pages: " & lngPages & vbCr & _ "Paragraphs: " & lngParagraphs & vbCr & _ "Lines: " & lngLines & vbCr & _ "Words: " & lngWords & vbCr & _ "Characters: " & lngCharacters & vbCr & _ "Characters with spaces: " & lngCharactersWithSpaces & vbCr & _ "Far east Characters: " & lngFarEastCharacters End Sub Even then, you will need to watch out for line breaks that are inserted by the email program. -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "Nikeel" wrote in message ... Hello I have a macro which excludes words inside tables and brackets from the general word count in a document. The problem is the macro is not in the right format (the writing appears red in Visual Basic Editor). Does anyone know the right format for the macro or how I can get it to be right? Any help is greatly appreciated, many thanks. The macro is as follows: Public Sub StatisticsExcludingTables() Dim tblItem As Word.Table Dim rngReplace As Word.Range Dim rngFound As Word.Range Dim lngCharacters As Long Dim lngCharactersWithSpaces As Long Dim lngFarEastCharacters As Long Dim lngLines As Long Dim lngPages As Long Dim lngParagraphs As Long Dim lngWords As Long ' Get the totals for the document With ActiveDocument lngCharacters = .ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = _ .ComputeStatistics(wdStatisticCharactersWithSpaces ) lngFarEastCharacters = _ .ComputeStatistics(wdStatisticFarEastCharacters) lngLines = .ComputeStatistics(wdStatisticLines) lngPages = .ComputeStatistics(wdStatisticPages) lngParagraphs = .ComputeStatistics(wdStatisticParagraphs) lngWords = .ComputeStatistics(wdStatisticWords) End With ' Subtract out the table statistics For Each tblItem In ActiveDocument.Tables With tblItem.Range lngCharacters = lngCharacters - _ .ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = lngCharactersWithSpaces - _ .ComputeStatistics(wdStatisticCharactersWithSpaces ) lngFarEastCharacters = lngFarEastCharacters - _ .ComputeStatistics(wdStatisticFarEastCharacters) lngLines = lngLines - .ComputeStatistics(wdStatisticLines) lngPages = lngPages - .ComputeStatistics(wdStatisticPages) lngParagraphs = lngParagraphs - _ .ComputeStatistics(wdStatisticParagraphs) lngWords = lngWords - .ComputeStatistics(wdStatisticWords) End With Next ' Search document for parenthesised words Set rngReplace = ActiveDocument.Content With rngReplace.Find .ClearFormatting .Replacement.ClearFormatting .Text = "\(*\)" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True ' Find all occurrences in the document Do While .Execute ' Exclude statistics the words in parenthesis Set rngFound = rngReplace.Duplicate With rngFound lngCharacters = lngCharacters - _ .ComputeStatistics(wdStatisticCharacters) lngCharactersWithSpaces = lngCharactersWithSpaces - _ .ComputeStatistics(wdStatisticCharactersWithSpaces ) lngFarEastCharacters = lngFarEastCharacters - _ .ComputeStatistics(wdStatisticFarEastCharacters) lngWords = lngWords - .ComputeStatistics(wdStatisticWords) End With ' Setup range to continue the search after ' the text that we just found rngReplace.Collapse wdCollapseEnd Loop End With MsgBox "Pages: " & lngPages & vbCr & _ "Paragraphs: " & lngParagraphs & vbCr & _ "Lines: " & lngLines & vbCr & _ "Words: " & lngWords & vbCr & _ "Characters: " & lngCharacters & vbCr & _ "Characters with spaces: " & lngCharactersWithSpaces & vbCr & _ "Far east Characters: " & lngFarEastCharacters End Sub |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Brackets around texts? What is that? | Formatting Long Documents | |||
Macro doesn't work | Microsoft Word Help | |||
Gery brackets on form fields | Microsoft Word Help | |||
How do I get rid of the grey brackets that appear with form fields | Tables | |||
Word 2003 prints gray brackets | Formatting Long Documents |