Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Nikeel
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.word.tables
Nikeel
 
Posts: n/a
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Brackets around texts? What is that? GH Formatting Long Documents 3 November 22nd 05 05:56 PM
Macro doesn't work Anna Microsoft Word Help 9 October 17th 05 10:25 PM
Gery brackets on form fields Dai_Tau_Lo Microsoft Word Help 2 April 26th 05 09:27 PM
How do I get rid of the grey brackets that appear with form fields Dai_Tau_Lo Tables 1 April 26th 05 06:42 PM
Word 2003 prints gray brackets James Formatting Long Documents 2 February 17th 05 10:01 AM


All times are GMT +1. The time now is 12:34 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"