Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Total Pages in Sheet

  1. #1
    New Member
    Join Date
    May 2002
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi,
    I'd like to know if there's a way (using VBA) to get the total number of pages of a sheet?
    I've tried difference variations of this code:

    HorizBreaks = Worksheets(1).HPageBreaks.Count
    HPages = HorizBreaks + 1
    VertBreaks = Worksheets(1).VPageBreaks.Count
    VPages = VertBreaks + 1
    NumPages = HPages * VPages

    and it still doesn't work. Any help you can give me would be greatly appreciated.

  2. #2
    MrExcel MVP Jay Petrulis's Avatar
    Join Date
    Mar 2002
    Location
    Chicago, IL USA
    Posts
    2,040
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Robert,

    PageCount = ExecuteExcel4Macro("Get.Document(50)")

    For more detail, follow the responses in this link.

    http://mrexcel.com/board/viewtopic.p...c=5067&forum=2

    Bye,
    Jay

  3. #3
    New Member
    Join Date
    May 2002
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    WOW.....really fast service....like 5 minutes fast......Thanks a million Jay...the code works awesome!

  4. #4
    New Member
    Join Date
    May 2002
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Jay,
    I'm using this in Access and I am making a connection to excel like this:

    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet

    'Setup Excel
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add
    Set xlSheet = xlBook.Worksheets(1)

    but when I try your code (which I think is right):

    intPageCount = xlApp.ExecuteExcel4Macro("Get.Document(50)")

    it returns 1.....any clue?

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •