delphi提取ppt文件里的文本函数,VBA中能正确执行,但delphi中提示出错。(100分)

  • 主题发起人 coolingxyz
  • 开始时间
C

coolingxyz

Unregistered / Unconfirmed
GUEST, unregistred user!
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 Sub


delphi代码


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中提示出错。哪位写过类似程序的朋友,看看,问题处在哪里?
 
问题已经解决

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.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;
finally
PptApp.ActiveWindow.Presentation.Saved := true;
PptApp.ActiveWindow.Close;
PptApp.Quit;
PptApp := null;
end;
end;
 
顶部