Search code examples
delphidelphi-10.1-berlin

Amount of Content Controls in Header


i need to know how i can get the amount of Content Controls in a Word Document Header. I tried this piece of code:

WinWord.ActiveDocument.Sections.Item(1).Headers.Item(wdHeaderFooterPrimary).Range.ContentControls.Count;

but it says 'undeclared identifier: wdHeaderFooterPrimary' although i have seen many solutions where this has been used to get into the header. Do you guys have an idea how to deal with this problem?


Solution

  • The unit in which you are getting this error needs to USE the type library import unit for MS Word, e.g. the supplied Word2000.Pas unit you should be able to find in your Delphi installation. As well as interfaces for the various MS Word objects, this unit also includes the definitions of various numeric constants like your one.

    You should be able to find Word2000.Pas and equivalent import units for various other versions of MS Word in the OCX\Servers folder of your Delphi install.

    You can, if you wish, generate the import unit yourself in the IDE by going to Component | Import Component | Import a Type Library and then selecting the Type Library for the version of Word you are using from the list on the Registered Type Libraries tab.