none
Problem counting pages in an email RRS feed

  • Question

  • I have a problem counting the pages in an email.  

    I get the current mail item, use its GetInspector.GetWordEditor, and cast that as a Word Document.  I then call the ComputeStatisitics method of the Word document in order to get the character count and the page count.  The problem is that the character count always gives a credible value but the page count always gives 1 despite the fact that when Outlook's print preview shows that the same email has 7 pages.

    I am using VB.net in VS 2010 and Outlook 2013.  

    I have the following references
    Interop.Offoce.dll .NET 2.1.0.0
    Interop.Outlook.dll  .NET 9.0.0.0
    Microsoft.Office.Interop.Word .NET 11.0.0.0

    (The add-in supports all version of Outlook from OL2003 but this counting feature is only available if OL2007 or higher is detected.)

    I set class level object

    Friend wrdDoc As Word.Document

    A button click gets the current mail item, gets its Word document, and performs the calculations.

    wrdDoc = CType(olMailItem.GetInspector.WordEditor,Word.Document)

    Dim lngCharactersInEmail = wrdDoc.ComputeStatistics(Word.WdStatistic.wdStatisticCharacters, False)
    Dim lngPages As Long = wrdDoc.ComputeStatistics(Word.WdStatistic.wdStatisticPages, True)

    Am I missing something?


    Mike VE

    Thursday, March 7, 2013 11:02 AM

Answers

  • I can verify the problem in Outlook 2013, where the same email that returned 4 pages with Outlook 2010 now only shows 1 page in 2013.
     
    I'll report it to the product group and report back anything I hear from them on it. If you want more prompt action you can try opening a support incident with MS on this. If they decide it's a bug you'd get reimbursed for the cost of the support incident.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Ken Slovak MVP" <=?utf-8?B?S2VuIFNsb3ZhayBNVlA=?=> wrote in message news:1c33a5d9-21a6-45fd-8ab3-a4f6a2a53c3e...
    Are you seeing the problem only in Outlook 2013?
     
    I tried equivalent code here in Outlook 2010 and I got 4 pages on the selected email. Print preview showed 5 pages, but that could be because a specific printer was alreadty selected.
     
    Try selecting various emails and running the following Outlook VBA code to see what you get:
     
    Sub worddocstats()
        Dim om As Outlook.MailItem
        Dim oi As Outlook.Inspector
        Dim doc As Word.document
       
        Set om = Application.ActiveExplorer.Selection(1)
        Set oi = om.GetInspector
        Set doc = oi.WordEditor
       
        Debug.Print doc.ComputeStatistics(wdStatisticCharacters, False)
        Debug.Print doc.ComputeStatistics(wdStatisticPages, True)
    End Sub

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Mike VE" <=?utf-8?B?TWlrZSBWRQ==?=> wrote in message news:3991f134-6078-473c-97f4-3364c0f3bec5...

    I have a problem counting the pages in an email.  

    I get the current mail item, use its GetInspector.GetWordEditor, and cast that as a Word Document.  I then call the ComputeStatisitics method of the Word document in order to get the character count and the page count.  The problem is that the character count always gives a credible value but the page count always gives 1 despite the fact that when Outlook's print preview shows that the same email has 7 pages.

    I am using VB.net in VS 2010 and Outlook 2013.  

    I have the following references
    Interop.Offoce.dll .NET 2.1.0.0
    Interop.Outlook.dll  .NET 9.0.0.0
    Microsoft.Office.Interop.Word .NET 11.0.0.0

    (The add-in supports all version of Outlook from OL2003 but this counting feature is only available if OL2007 or higher is detected.)

    I set class level object

    Friend wrdDoc As Word.Document

    A button click gets the current mail item, gets its Word document, and performs the calculations.

    wrdDoc = CType(olMailItem.GetInspector.WordEditor,Word.Document)

    Dim lngCharactersInEmail = wrdDoc.ComputeStatistics(Word.WdStatistic.wdStatisticCharacters, False)
    Dim lngPages As Long = wrdDoc.ComputeStatistics(Word.WdStatistic.wdStatisticPages, True)

    Am I missing something?


    Mike VE


    Ken Slovak MVP - Outlook

    Ken Slovak MVP - Outlook
    • Marked as answer by Mike VE Friday, March 8, 2013 6:45 PM
    Thursday, March 7, 2013 7:37 PM
    Moderator

All replies

  • Are you seeing the problem only in Outlook 2013?
     
    I tried equivalent code here in Outlook 2010 and I got 4 pages on the selected email. Print preview showed 5 pages, but that could be because a specific printer was alreadty selected.
     
    Try selecting various emails and running the following Outlook VBA code to see what you get:
     
    Sub worddocstats()
        Dim om As Outlook.MailItem
        Dim oi As Outlook.Inspector
        Dim doc As Word.document
       
        Set om = Application.ActiveExplorer.Selection(1)
        Set oi = om.GetInspector
        Set doc = oi.WordEditor
       
        Debug.Print doc.ComputeStatistics(wdStatisticCharacters, False)
        Debug.Print doc.ComputeStatistics(wdStatisticPages, True)
    End Sub

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Mike VE" <=?utf-8?B?TWlrZSBWRQ==?=> wrote in message news:3991f134-6078-473c-97f4-3364c0f3bec5...

    I have a problem counting the pages in an email.  

    I get the current mail item, use its GetInspector.GetWordEditor, and cast that as a Word Document.  I then call the ComputeStatisitics method of the Word document in order to get the character count and the page count.  The problem is that the character count always gives a credible value but the page count always gives 1 despite the fact that when Outlook's print preview shows that the same email has 7 pages.

    I am using VB.net in VS 2010 and Outlook 2013.  

    I have the following references
    Interop.Offoce.dll .NET 2.1.0.0
    Interop.Outlook.dll  .NET 9.0.0.0
    Microsoft.Office.Interop.Word .NET 11.0.0.0

    (The add-in supports all version of Outlook from OL2003 but this counting feature is only available if OL2007 or higher is detected.)

    I set class level object

    Friend wrdDoc As Word.Document

    A button click gets the current mail item, gets its Word document, and performs the calculations.

    wrdDoc = CType(olMailItem.GetInspector.WordEditor,Word.Document)

    Dim lngCharactersInEmail = wrdDoc.ComputeStatistics(Word.WdStatistic.wdStatisticCharacters, False)
    Dim lngPages As Long = wrdDoc.ComputeStatistics(Word.WdStatistic.wdStatisticPages, True)

    Am I missing something?


    Mike VE


    Ken Slovak MVP - Outlook
    Thursday, March 7, 2013 7:12 PM
    Moderator
  • I can verify the problem in Outlook 2013, where the same email that returned 4 pages with Outlook 2010 now only shows 1 page in 2013.
     
    I'll report it to the product group and report back anything I hear from them on it. If you want more prompt action you can try opening a support incident with MS on this. If they decide it's a bug you'd get reimbursed for the cost of the support incident.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Ken Slovak MVP" <=?utf-8?B?S2VuIFNsb3ZhayBNVlA=?=> wrote in message news:1c33a5d9-21a6-45fd-8ab3-a4f6a2a53c3e...
    Are you seeing the problem only in Outlook 2013?
     
    I tried equivalent code here in Outlook 2010 and I got 4 pages on the selected email. Print preview showed 5 pages, but that could be because a specific printer was alreadty selected.
     
    Try selecting various emails and running the following Outlook VBA code to see what you get:
     
    Sub worddocstats()
        Dim om As Outlook.MailItem
        Dim oi As Outlook.Inspector
        Dim doc As Word.document
       
        Set om = Application.ActiveExplorer.Selection(1)
        Set oi = om.GetInspector
        Set doc = oi.WordEditor
       
        Debug.Print doc.ComputeStatistics(wdStatisticCharacters, False)
        Debug.Print doc.ComputeStatistics(wdStatisticPages, True)
    End Sub

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Mike VE" <=?utf-8?B?TWlrZSBWRQ==?=> wrote in message news:3991f134-6078-473c-97f4-3364c0f3bec5...

    I have a problem counting the pages in an email.  

    I get the current mail item, use its GetInspector.GetWordEditor, and cast that as a Word Document.  I then call the ComputeStatisitics method of the Word document in order to get the character count and the page count.  The problem is that the character count always gives a credible value but the page count always gives 1 despite the fact that when Outlook's print preview shows that the same email has 7 pages.

    I am using VB.net in VS 2010 and Outlook 2013.  

    I have the following references
    Interop.Offoce.dll .NET 2.1.0.0
    Interop.Outlook.dll  .NET 9.0.0.0
    Microsoft.Office.Interop.Word .NET 11.0.0.0

    (The add-in supports all version of Outlook from OL2003 but this counting feature is only available if OL2007 or higher is detected.)

    I set class level object

    Friend wrdDoc As Word.Document

    A button click gets the current mail item, gets its Word document, and performs the calculations.

    wrdDoc = CType(olMailItem.GetInspector.WordEditor,Word.Document)

    Dim lngCharactersInEmail = wrdDoc.ComputeStatistics(Word.WdStatistic.wdStatisticCharacters, False)
    Dim lngPages As Long = wrdDoc.ComputeStatistics(Word.WdStatistic.wdStatisticPages, True)

    Am I missing something?


    Mike VE


    Ken Slovak MVP - Outlook

    Ken Slovak MVP - Outlook
    • Marked as answer by Mike VE Friday, March 8, 2013 6:45 PM
    Thursday, March 7, 2013 7:37 PM
    Moderator
  • Thanks for that Ken.  

    Yes I can confirm that it only seems to happen in Outlook 2013 which is a big relief as the client is still on OL2007.  The OL2013 documentation did not suggest there was anything different and it never even occurred to me that it could be a bug.  It great to have this confirmed by someone of your experience.  I'll look at raising a support issue.


    Mike VE

    Friday, March 8, 2013 6:44 PM
  • A bug has been opened on this problem. There's no projected fix date at this time, the bug has just been opened for triage.

    If any customer has a pressing need for a hotfix for this bug they should open a support case, and reference this thread and a related bug. The thread is linked to the bug.


    Ken Slovak MVP - Outlook

    Monday, March 18, 2013 9:23 PM
    Moderator