Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting Pages through VBA Code - Need Help

Status
Not open for further replies.

Kamstars

Programmer
Dec 3, 2003
6
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top