查询和获得当前页号。比如查“ABC”,则需要获得“ABC”在word中的多少页。
procedure TForm1.Button2Click(Sender: TObject);
var
  WordApp: Variant;//word对象
  Jpath:string;//word文件路径
  Jword:string;//要查询的字段
  myrange:variant;
  flag:integer;//文档中是否有所查字段的判断标志
  i:integer;//字段所在的当前页号
begin
 try
  Jpath:=edit1.text;//获得WORD文件路径
  Jword:=edit2.Text;//获得所查字段
  WordApp:=CreateOleObject('Word.Application');
  WordApp.Documents.Open(Jpath);
  memo1.Lines.clear;
  myRange:=WordApp.Documents.Content;
  flag:=0;
  while myRange.Find.Execute(FindText:=Jword,Forward:=True) <> False do//查询
    begin
      i:=myRange.Information(wdActiveEndPageNumber);//获得字段所在页号
      memo1.Lines.add(Jword+'在第'+inttostr(i)+'页。');
      flag:=flag+1;
    end;
  if flag=0 then
    application.messagebox('没有找到。','查询结果',mb_ok);
 finally
  wordApp.Quit;
  wordApp:=unassigned;
 end;
end;
现在的问题是wdActiveEndPageNumber报错说是没有定义的。(我在uses里已经加入了ComObj,应该不是COMOBJ的问题)
以下3句话的用法不太明确,看别人用VBA写了个类似的是这样用的,所以也就像这样用
1 myRange:=WordApp.Documents.Content;(是否需要定义这个myRange)
2 while myRange.Find.Execute(FindText:=Jword,Forward:=True) <> False do (查询是否这样写)
3 i:=myRange.Information(wdActiveEndPageNumber);(是否为获得当前页号)
请指点以上几句的具体用法或者这个问题的解决方法。现在程序出错说wdActiveEndPageNumber找不到,但是别人用VBA这么写就可以,谢谢!