views:

230

answers:

0

Hello,

I'm writing an application in Delphi (have two over revisions of it written in both C# and Visual Basic, also). In my C# and Visual Basic version, I did something like the following to loop through the header/footer FieldCodes:

    // Supress filename, date and username field codes in headers
    fieldCount = WordApp.ActiveDocument.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields.Count;
    for (Int32 x = 1; x <= fieldCount; x++)
    {
        if ((WordApp.ActiveDocument.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields[x].Type == Microsoft.Office.Interop.Word.WdFieldType.wdFieldDate) ||
            (WordApp.ActiveDocument.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields[x].Type == Microsoft.Office.Interop.Word.WdFieldType.wdFieldFileName) ||
            (WordApp.ActiveDocument.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields[x].Type == Microsoft.Office.Interop.Word.WdFieldType.wdFieldUserName))
        {
            WordApp.ActiveDocument.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields[x].Select();
            WordApp.Selection.TypeText("{ " + WordApp.ActiveDocument.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields[x].Code.Text + " }");
        }
    }

In my Delphi one I'm doing the same kind of routine. But, I've got a Word file that I'm trying to process and it has a Date FieldCode in the Header. My code is not finding the field code for some odd reason. It says there's no Fields in the Header.

Does anyone know if there's such thing as like hidden FieldCodes, or something that would cause these to not show up in my code?

Thanks, Ryan