A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

wordcount macro for tables and brackets



 
 
Thread Tools Display Modes
  #1  
Old December 27th, 2005, 04:52 PM posted to microsoft.public.word.tables
external usenet poster
 
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  
Old December 30th, 2005, 03:21 PM posted to microsoft.public.word.tables
external usenet poster
 
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  
Old December 30th, 2005, 07:43 PM posted to microsoft.public.word.tables
external usenet poster
 
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




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
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, 2005 05:56 PM
macro query cancel causes error Alex Pavluck General Discussion 1 November 2nd, 2005 04:38 PM
Macro doesn't work Anna General Discussion 9 October 17th, 2005 10:25 PM
Remove text in brackets from query JanetF Running & Setting Up Queries 17 August 16th, 2005 04:07 AM
Extract Text Outside of Brackets Frank Kabel Worksheet Functions 2 February 11th, 2004 07:38 AM


All times are GMT +1. The time now is 08:46 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.