VBA中的宏Sub GetPptText()
    Dim m, n, i, j As Integer
    Dim s As String    n = ActiveWindow.Presentation.Slides.Count
    For i = 1 To n
      m = ActiveWindow.Presentation.Slides(i).Shapes.Count
      For j = 1 To m
        If ActiveWindow.Presentation.Slides(i).Shapes(j).HasTextFrame Then
          s = s & ActiveWindow.Presentation.Slides(i).Shapes(j).TextFrame.TextRange.Text & "|"
        End If
      Next
    Next    MsgBox s
End Subdelphi代码
function ReadPPt(sName: string): string;
var
  n,m,i,j: integer;
  PptApp: OleVariant;
begin
  try
    PptApp := CreateOleObject('PowerPoint.Application');
    PptApp.Visible := true;    PptApp.Presentations.Open(sName);
    n := PptApp.ActiveWindow.Presentation.Slides.Count;    for i:=1 to n do
    begin
      m := PptApp.ActiveWindow.Presentation.Slides(i).Shapes.Count;//这里提示对象没有找到
      for j:=1 to m do
      begin
        If PptApp.ActiveWindow.Presentation.Slides(i).Shapes(j).HasTextFrame Then
          result := PptApp.ActiveWindow.Presentation.Slides(i).Shapes(j).TextFrame.TextRange.Text +#$D#$A;
      end;
    end;  finally
    PptApp.Presentation.Saved := true;
    PptApp.Presentation.Close;
    PptApp.Quit;
    PptApp := null;
  end;
end;delphi提取ppt文件里的文本函数,VBA中能正确执行,但delphi中提示出错。哪位写过类似程序的朋友,看看,问题处在哪里?

解决方案 »

  1.   

    数组前加Item
    如:ActiveWindow.Presentation.Slides.Item(i).Shapes.Item(j).TextFrame参考一下Servers页的TPowerPointApplication控件的属性和方法
      

  2.   

    要么试试看,@!#*^*!%#  as _Slide ?
      

  3.   

    数组前加Item 
    如:ActiveWindow.Presentation.Slides.Item(i).Shapes.Item(j).TextFrame 参考一下Servers页的TPowerPointApplication控件的属性和方法up
    up
      

  4.   

    正确答案:function TFrmMain.ReadPPt(sName: string): string;
    var
      n,m,i,j: integer;
      PptApp: OleVariant;
    begin
      try
        PptApp := CreateOleObject('PowerPoint.Application'); 
        PptApp.Visible := true;     PptApp.Presentations.Open(sName);
        n := PptApp.ActiveWindow.Presentation.Slides.Count;    for i:=1 to n do
        begin
          m := PptApp.ActiveWindow.Presentation.Slides.item(i).Shapes.Count;
          for j:=1 to m do
          begin
            If PptApp.ActiveWindow.Presentation.Slides.item(i).Shapes.item(j).HasTextFrame Then
              result:=result+PptApp.ActiveWindow.Presentation.Slides.item(i).Shapes.item(j).TextFrame.TextRange.Text +#$D#$A;
          end;
        end;    PptApp.ActiveWindow.Presentation.Saved := true;
        PptApp.ActiveWindow.Close;
      except
        result := '';
      end;
    end;
      

  5.   

    正确答案: function TFrmMain.ReadPPt(sName: string): string; 
    var 
      n,m,i,j: integer; 
      PptApp: OleVariant; 
    begin 
      try 
        PptApp := CreateOleObject('PowerPoint.Application'); 
        PptApp.Visible := true;     PptApp.Presentations.Open(sName); 
        n := PptApp.ActiveWindow.Presentation.Slides.Count;     for i:=1 to n do 
        begin 
          m := PptApp.ActiveWindow.Presentation.Slides.item(i).Shapes.Count; 
          for j:=1 to m do 
          begin 
            If PptApp.ActiveWindow.Presentation.Slides.item(i).Shapes.item(j).HasTextFrame Then 
              result:=result+PptApp.ActiveWindow.Presentation.Slides.item(i).Shapes.item(j).TextFrame.TextRange.Text +#$D#$A; 
          end; 
        end;     PptApp.ActiveWindow.Presentation.Saved := true; 
        PptApp.ActiveWindow.Close; 
      except 
        result := ''; 
      end; 
    end;
      

  6.   


    我的软件也写好了,用这个软件可以自动读取目录下的doc,ppt,各类文本等格式的文件内容,然后生成html页面。主要目的就是做个资源共享的网站,现在我把网站挂上去了。地址是:http://www.mflwk.cn/