shieldose.blogg.se

How to use office word to automaticly number each page
How to use office word to automaticly number each page






how to use office word to automaticly number each page

If oSec.Index = NumSections Then nEndPg = nEndPg + 1 VARIANT vInfo = oSecRange.GetInformation(3L) //wdActiveEndPageNumber=3 Long NumPages=0 //Number of pages in the section. Iterate the collection of sections in the document to retrieve the page VOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt, vOpt, vOpt,vOpt,vOpt,vOpt,vOpt) _Document oDoc = oDocs.Open(COleVariant("c:\\mydoc.doc"), vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt, vOpt, vOpt,vOpt,vOpt,vOpt,vOpt) _Document oDoc = oDocs.Open(COleVariant("c:\\mydoc.docx"), OWord.CreateDispatch("Word.Application") COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR) In Word 2000, add the following line: #include "MSWord9.h"Īdd the following code to CAutoProjectDlg::OnRun() in AutoProjectDlg.cpp. In Word 2002 and in later versions of Word, add the following line: #include "MSWord.h" You must remove the Excel automation library.Īt the top of AutoProjectDlg.cpp, add one of the following lines: The code displays the page count for each section in the Immediate window.įollow steps 1 through 12 in the following article in the Microsoft Knowledge Base to create a sample project that uses the IDispatch interfaces and member functions that are defined in the MSWord9.olb type library. Press F5 to run the application, and click the button on the form.

how to use office word to automaticly number each page

'Close the document without saving changes and quit Word. If oSec.Index = NumSections Then nEndPg = nEndPg + 1ĭebug.Print "Section " & oSec.Index & " -", _ NEndPg = (3) - 1 'wdActiveEndPageNumber=3 The results areĭim nStartPg As Integer, nEndPg As Integer, nSecPages As Integer 'document and compute the page count in that section. 'Iterate each section in the document to retrieve the end page of the 'For Word 2007, change the path to "c:\mydoc.docx" Set oApp = CreateObject("Word.Application") Form1 is created by default.Īdd a command button to Form1, and add the following code to the button's Click event: Dim oApp As Object In Visual Basic, create a new Standard EXE project. Therefore, when you insert section breaks while creating the C:\Mydoc.doc Word document for testing the sample code, you should choose Next Page as the Section Break type. NOTE: The sample code assumes that a section break forces a new page break and that each page contains no more than one section. For testing the sample code, either create a new document with multiple sections and multiple pages and save it as C:\Mydoc.doc, or change the document path in the code to reference one of your existing Word documents. The following sample code uses a document that is saved to C:\Mydoc.doc. This article describes how you can use automation with Word to determine the number of pages in each section of a document.








How to use office word to automaticly number each page