私は基本的に、各ページの単語数をフッターに入れ、それを各ページの合計単語数に追加するドキュメントの累積単語数を作成しようとしています。いろいろ調べてみたところ、Word は実際にはすべての人に対して同じようにページを処理するわけではなく、個々のページにアクセスするためのインターフェイスがないことがわかりました。
現在、各ページを改ページで区切ろうとしているため、ページ間に明確な区切り文字がありますが、これらをループする方法はまだ見つかりません。手がかりはありますか?
私が持っているコードを投稿するつもりですが、現在は単語数を取得するためだけです。方法がわからないため、改ページを循環させる適切な試みはありません。
Sub getPageWordCount()
Dim iPgNum As Integer
Dim sPgNum As String
Dim ascChar As Integer
Dim rngPage As Range
Dim iBeginPage As Integer
Dim iEndPage As Integer
' Go to start of document and make sure its paginated correctly.
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
ActiveDocument.Repaginate
' Loop through the number of pages in the document.
For iPgNum = 2 To Selection.Information(wdNumberOfPagesInDocument)
sPgNum = CStr(iPgNum)
iBeginPage = Selection.Start
' Go to next page
Selection.GoTo wdGoToPage, wdGoToAbsolute, sPgNum
' and to the last character of the previous page...
Selection.MoveLeft wdCharacter, 1, wdMove
iEndPage = Selection.Start
' Retrieve the character code at insertion point.
Set rngPage = ActiveDocument.Range(iBeginPage, iEndPage)
MsgBox rngPage.ComputeStatistics(wdStatisticWords)
'rngPage.Footers(wdHeaderFooterPrimary).Range.Text = rngPage.ComputeStatistics(wdStatisticWords)
'ActiveDocument.Sections(2).Footers
' Check the character code for hard page break or text.
Next
' ActiveDocument.Sections(2).Footers(wdHeaderFooterPrimary).Range.Text = "bob" 'Testing
End Sub