I am trying to count pages in a word document after performing a merge. The name of the document, page numbers, and date are supposed to print out to a text file. The problem is that each time I am only coming up with 1 page. Are you able to tell me what I am doing wrong below? How can I get the new merged document to print out the correct number of pages?
Thanks for your help.
Sub mcrPerformMerge()
Dim FlnNamWDate As String
Dim Date1 As Date
Dim Month1 As String
Dim Day1 As String
Dim Year1 As String
Dim Date2 As String
Dim varNumberPages As Variant
Close #1
Open "h:\LetterPageInfo.txt" For Append As #1
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Date1 = Date
Month1 = DatePart("m", Date1)
Day1 = Right("0" & DatePart("d", Date1), 2)
Year1 = Right(DatePart("yyyy", Date1), 2)
Date2 = Month1 & Day1 & Year1
FlnNamWDate = "H:\EnrollmentClosedLetter " & Date2 & ".doc"
ActiveDocument.SaveAs FileName:=FlnNamWDate, FileFormat:=wdFormatDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
varNumberPages = ActiveDocument.Content.Information(wdActiveEndAdjustedPageNumber)
Print #1, "EnrollmentClosedLetter ", varNumberPages, Date$
ActiveDocument.Close
Application.Quit SaveChanges:=wdDoNoSaveChanges
Close #1
End Sub
Thanks for your help.
Sub mcrPerformMerge()
Dim FlnNamWDate As String
Dim Date1 As Date
Dim Month1 As String
Dim Day1 As String
Dim Year1 As String
Dim Date2 As String
Dim varNumberPages As Variant
Close #1
Open "h:\LetterPageInfo.txt" For Append As #1
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Date1 = Date
Month1 = DatePart("m", Date1)
Day1 = Right("0" & DatePart("d", Date1), 2)
Year1 = Right(DatePart("yyyy", Date1), 2)
Date2 = Month1 & Day1 & Year1
FlnNamWDate = "H:\EnrollmentClosedLetter " & Date2 & ".doc"
ActiveDocument.SaveAs FileName:=FlnNamWDate, FileFormat:=wdFormatDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
varNumberPages = ActiveDocument.Content.Information(wdActiveEndAdjustedPageNumber)
Print #1, "EnrollmentClosedLetter ", varNumberPages, Date$
ActiveDocument.Close
Application.Quit SaveChanges:=wdDoNoSaveChanges
Close #1
End Sub