From: andreas on
Dear Experts:

I would like to paste the contents of the MsgBox into a new Document
with the following heading:

The document statistics for the current document <document name on
which the macro was run> is as follows:
(This heading should be wdStyleNormal and bold formatted).

Each statisical data should be on its own paragraph (wdStyleNormal),
not bold.

Help is much appreciated. Thank you very much in advance. Regards,
Andreas


Public Sub DocumentStatistics()
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
Dim newDoc As Document
Dim strMsg As String


If MsgBox("Would you like to list all Document Statistics at the
end of the document?" & vbCrLf & _
"Would you like to continue?", vbQuestion + vbYesNo, "List all
Document statistics") = vbNo Then
Exit Sub

End If

' 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)

MsgBox lngCharacters & " Characters " & lngLines & " Lines " &
lngWords & " Words" & lngParagraphs & " Paragraphs"
End With

End Sub
From: Doug Robbins - Word MVP on
Use:

Dim Source As Document, Target As Document
Dim lngCharacters
Dim lngCharactersWithSpaces
Dim lngFarEastCharacters
Dim lngLines
Dim lngPages
Dim lngParagraphs
Dim lngWords


If MsgBox("Would you like to list all Document Statistics at the end of the
document?" & vbCrLf & _
"Would you like to continue?", vbQuestion + vbYesNo, "List all Document
statistics") = vbNo Then
Exit Sub
Else
Set Source = ActiveDocument
Set Target = Documents.Add
With Source
' Get the totals for the document
lngCharacters = Format(.ComputeStatistics(wdStatisticCharacters),
"#,###")
lngCharactersWithSpaces = _
Format(.ComputeStatistics(wdStatisticCharactersWithSpaces),
"#,###")
lngFarEastCharacters = _
Format(.ComputeStatistics(wdStatisticFarEastCharacters),
"#,###")
lngLines = Format(.ComputeStatistics(wdStatisticLines), "#,###")
lngPages = Format(.ComputeStatistics(wdStatisticPages), "#,###")
lngParagraphs = Format(.ComputeStatistics(wdStatisticParagraphs),
"#,###")
lngWords = Format(.ComputeStatistics(wdStatisticWords), "#,###")
End With
With Target
.Range.InsertAfter "The document statistics for the current document
" _
& Source.Name & " are as follows:" & vbCr & lngCharacters & "
Characters " & vbCr & _
lngLines & " Lines " & vbCr & lngWords & " Words" & vbCr &
lngParagraphs & " Paragraphs"
.Range.Paragraphs(1).Range.Font.Bold = True
End With
End If


--
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, originally posted via msnews.microsoft.com

"andreas" <andreas.hermle(a)gmx.de> wrote in message
news:aae3a752-fbf2-4785-b6b9-6ed990075132(a)o8g2000yqo.googlegroups.com...
> Dear Experts:
>
> I would like to paste the contents of the MsgBox into a new Document
> with the following heading:
>
> The document statistics for the current document <document name on
> which the macro was run> is as follows:
> (This heading should be wdStyleNormal and bold formatted).
>
> Each statisical data should be on its own paragraph (wdStyleNormal),
> not bold.
>
> Help is much appreciated. Thank you very much in advance. Regards,
> Andreas
>
>
> Public Sub DocumentStatistics()
> 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
> Dim newDoc As Document
> Dim strMsg As String
>
>
> If MsgBox("Would you like to list all Document Statistics at the
> end of the document?" & vbCrLf & _
> "Would you like to continue?", vbQuestion + vbYesNo, "List all
> Document statistics") = vbNo Then
> Exit Sub
>
> End If
>
> ' 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)
>
> MsgBox lngCharacters & " Characters " & lngLines & " Lines " &
> lngWords & " Words" & lngParagraphs & " Paragraphs"
> End With
>
> End Sub

From: andreas on
On May 14, 10:16 pm, "Doug Robbins - Word MVP"
<d...(a)REMOVECAPSmvps.org> wrote:
> Use:
>
> Dim Source As Document, Target As Document
> Dim lngCharacters
> Dim lngCharactersWithSpaces
> Dim lngFarEastCharacters
> Dim lngLines
> Dim lngPages
> Dim lngParagraphs
> Dim lngWords
>
> If MsgBox("Would you like to list all Document Statistics at the end of the
> document?" & vbCrLf & _
>     "Would you like to continue?", vbQuestion + vbYesNo, "List all Document
> statistics") = vbNo Then
>     Exit Sub
> Else
>     Set Source = ActiveDocument
>     Set Target = Documents.Add
>     With Source
>         ' Get the totals for the document
>         lngCharacters = Format(.ComputeStatistics(wdStatisticCharacters),
> "#,###")
>         lngCharactersWithSpaces = _
>             Format(.ComputeStatistics(wdStatisticCharactersWithSpaces),
> "#,###")
>         lngFarEastCharacters = _
>             Format(.ComputeStatistics(wdStatisticFarEastCharacters),
> "#,###")
>         lngLines = Format(.ComputeStatistics(wdStatisticLines), "#,###")
>         lngPages = Format(.ComputeStatistics(wdStatisticPages), "#,###")
>         lngParagraphs = Format(.ComputeStatistics(wdStatisticParagraphs),
> "#,###")
>         lngWords = Format(.ComputeStatistics(wdStatisticWords), "#,###")
>     End With
>     With Target
>         .Range.InsertAfter "The document statistics for the current document
> " _
>         & Source.Name & " are as follows:" & vbCr & lngCharacters & "
> Characters " & vbCr & _
>         lngLines & " Lines " & vbCr & lngWords & " Words" & vbCr &
> lngParagraphs & "  Paragraphs"
>         .Range.Paragraphs(1).Range.Font.Bold = True
>     End With
> End If
>
> --
> 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, originally posted via msnews.microsoft.com
>
> "andreas" <andreas.her...(a)gmx.de> wrote in message
>
> news:aae3a752-fbf2-4785-b6b9-6ed990075132(a)o8g2000yqo.googlegroups.com...
>
>
>
> > Dear Experts:
>
> > I would like to paste the contents of the MsgBox into a new Document
> > with the following heading:
>
> > The document statistics for the current document <document name on
> > which the macro was run> is as follows:
> > (This heading should be wdStyleNormal and bold formatted).
>
> > Each statisical data should be on its own paragraph (wdStyleNormal),
> > not bold.
>
> > Help is much appreciated. Thank you very much in advance. Regards,
> > Andreas
>
> > Public Sub DocumentStatistics()
> > 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
> > Dim newDoc As Document
> > Dim strMsg As String
>
> >    If MsgBox("Would you like to list all Document Statistics at the
> > end of the document?" & vbCrLf & _
> > "Would you like to continue?", vbQuestion + vbYesNo, "List all
> > Document statistics") = vbNo Then
> >    Exit Sub
>
> >    End If
>
> > ' 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)
>
> > MsgBox lngCharacters & " Characters " & lngLines & " Lines " &
> > lngWords & " Words" & lngParagraphs & "  Paragraphs"
> > End With
>
> > End Sub- Hide quoted text -
>
> - Show quoted text -

Hi Dough,

great job. Thank you very much for your swift and professional help.
You truly deserve your Word MVP designation!
Have a nice day. Regards, Andreas