VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get MS Word Document Page Count Pro grammatically

by Gehan Fernando (47 Submissions)
Category: Miscellaneous
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Tue 7th December 2010
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Get MS Word Document Page Count Pro grammatically

API Declarations


using System.Windows.Forms;

using Word = Microsoft.Office.Interop.Word;

Rate Get MS Word Document Page Count Pro grammatically



{
    public partial class FormCount : Form
    {
        public FormCount()
        {
            InitializeComponent();
        }

        private void buttonGetCount_Click(object sender, EventArgs e)
        {
            Word.ApplicationClass WordApp = new Word.ApplicationClass();

            object fileName = textBoxPath.Text;
            object readOnly = false;
            object isVisible = false;

            object missing = System.Reflection.Missing.Value;

            Word.Document aDoc = WordApp.Documents.Open(ref fileName,
                                        ref missing, ref readOnly, ref missing,
                                        ref missing, ref missing, ref missing,
                                        ref missing, ref missing, ref missing, 
                                        ref missing, ref isVisible, ref missing, 
                                        ref missing, ref missing, ref missing);

            Word.WdStatistic stat = Word.WdStatistic.wdStatisticPages;
            int num = aDoc.ComputeStatistics(stat, ref missing);

            MessageBox.Show("The number of pages in doc is " + num.ToString("00"),
            this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);

            WordApp = null;
        }
    }
}

Download this snippet    Add to My Saved Code

Get MS Word Document Page Count Pro grammatically Comments

No comments have been posted about Get MS Word Document Page Count Pro grammatically. Why not be the first to post a comment about Get MS Word Document Page Count Pro grammatically.

Post your comment

Subject:
Message:
0/1000 characters