Macro for DocumentStatistics: Contents of MsgBox in a new document

A

andreas

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
 
D

Doug Robbins - Word MVP

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
 
A

andreas

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
















- 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top