Seems like the base index of the Item
collection is 1 (not 0). So you need to iterate from 1 to WordDocument.Fields.Count
e.g.:
procedure TForm1.Button1Click(Sender: TObject);
var
WordApp, WordDocument, Field: OleVariant;
I: Integer;
begin
WordApp := CreateOleObject('Word.Application');
try
WordDocument := WordApp.Documents.Open('C:\MyDoc.doc');
if WordDocument.Fields.Count >= 1 then
for I := 1 to WordDocument.Fields.Count do
begin
Field := WordDocument.Fields.Item(I);
ShowMessage(Field.Code);
end;
finally
WordApp.Quit;
end;
end;
Trying to access WordDocument.Fields.Item(0)
results an error:
The requested member of the collection does not exist.
I got that hint from here