大家帮忙排错,网上查了好久都是同样的代码,但是没有说是错的。(50)

  • 主题发起人 主题发起人 maozhuxi
  • 开始时间 开始时间
M

maozhuxi

Unregistered / Unconfirmed
GUEST, unregistred user!
PPtP.ConnectTo(pptA.Presentations.Open('D:/my_pro/out_ppt/1.ppt', msoFalse, msoFalse, msoTrue));我是想打开ppt文件,但是运行到这里就报未知错误。下面是我的源代码:button1和button2的用处一样都是想打开ppt,但是就是报错,实在没办法。unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,comobj,office2000, OleServer, PowerPointXP;type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; OpenDialog1: TOpenDialog; PowerPointApplication1: TPowerPointApplication; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var PPT, PP: Variant; i,j:integer; s:string;begin PPT := CreateOleObject('PowerPoint.Application') ; PPT.visible:=msoTrue; showmessage('qq'); //pp := PPT.Presentations.Open('D:/my_pro/out_ppt/1.ppt', True, True, False); opendialog1.Execute; pp := ppt.Presentations.Open(opendialog1.FileName,msoFalse,msoFalse, msoTrue); for I := 1 to pp.Slides.Count do for J := 1 to pp.Slides.Item(I).Shapes.Count do if pp.Slides.Item(I).Shapes.Item(J).TextFrame.HasText then S := S + #13#10 + pp.Slides.Item(I).Shapes.Item(J).TextFrame.TextRange.Text; Memo1.Text := S; PPT.Quit; PP := UnAssigned; PPT := UnAssigned;end;procedure TForm1.Button2Click(Sender: TObject);varpptA: TPowerPointApplication;pptP: TPowerPointPresentation;ssSet: SlideShowSettings;ssWin: SlideShowWindow;beginpptA := TPowerPointApplication.Create(self);pptA.Visible := msoTrue;PPtP.ConnectTo(pptA.Presentations.Open('D:/my_pro/out_ppt/1.ppt', msoFalse, msoFalse, msoTrue));ssSet := PPtP.SlideShowSettings;ssSet.LoopUntilStopped := msoFalse;ssSet.ShowType := ppShowTypeSpeaker;ssSet.Run;ssWin := PPtP.SlideShowWindow;end;end.
 
PPtP对象未创建修改如下 pptA := TPowerPointApplication.Create(self); pptP := TPowerPointPresentation.Create(Self); try pptA.Visible := msoTrue; opendialog1.Execute; PPtP.ConnectTo( pptA.Presentations.Open(opendialog1.FileName, msoFalse, msoFalse, msoTrue) ); ssSet := PPtP.SlideShowSettings; ssSet.LoopUntilStopped := msoFalse; ssSet.ShowType := ppShowTypeSpeaker; ssSet.Run; ssWin := PPtP.SlideShowWindow; finally pptA.Free; pptP.Free; end;
 
还是同样的报错误代码按照你说的修改如下:procedure TForm1.Button2Click(Sender: TObject);varpptA: TPowerPointApplication;pptP: TPowerPointPresentation;ssSet: SlideShowSettings;ssWin: SlideShowWindow;begin pptA := TPowerPointApplication.Create(self); pptP := TPowerPointPresentation.Create(Self); try pptA.Visible := msoTrue; opendialog1.Execute; PPtP.ConnectTo( pptA.Presentations.Open(opendialog1.FileName, msoFalse, msoFalse, msoTrue) ); ssSet := PPtP.SlideShowSettings; ssSet.LoopUntilStopped := msoFalse; ssSet.ShowType := ppShowTypeSpeaker; ssSet.Run; ssWin := PPtP.SlideShowWindow; finally pptA.Free; pptP.Free; end; end;
 
可以运行还是在这里报错: PPtP.ConnectTo( pptA.Presentations.Open(opendialog1.FileName, msoFalse, msoFalse, msoTrue) );
 
我再次试了下,成功以幻灯片的形式打开了
 
这是我的全部代码,为什么我的就要报错呢?unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,comobj,office2000, OleServer, PowerPointXP;type TForm1 = class(TForm) Memo1: TMemo; OpenDialog1: TOpenDialog; PowerPointApplication1: TPowerPointApplication; Button2: TButton; procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);varpptA: TPowerPointApplication;pptP: TPowerPointPresentation;ssSet: SlideShowSettings;ssWin: SlideShowWindow;begin pptA := TPowerPointApplication.Create(self); pptP := TPowerPointPresentation.Create(Self); try pptA.Visible := msoTrue; opendialog1.Execute; PPtP.ConnectTo( pptA.Presentations.Open(opendialog1.FileName, msoFalse, msoFalse, msoTrue));//这里就报错 ssSet := PPtP.SlideShowSettings; ssSet.LoopUntilStopped := msoFalse; ssSet.ShowType := ppShowTypeSpeaker; ssSet.Run; ssWin := PPtP.SlideShowWindow; finally pptA.Free; pptP.Free; end; end;end.
 
try RzOpenDialog1.Execute; pptA := TPowerPointApplication.Create(self); pptP := TPowerPointPresentation.Create(Self); pptA.Visible := msoTrue; PPtP.ConnectTo( pptA.Presentations.Open(RzOpenDialog1.FileName, msoFalse, msoFalse, msoTrue));//这里就报错 ssSet := PPtP.SlideShowSettings; ssSet.LoopUntilStopped := msoFalse; ssSet.ShowType := ppShowTypeSpeaker; ssSet.Run; ssWin := PPtP.SlideShowWindow; finally pptA.Free; pptP.Free; end; 我这边没问题
 
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Comobj, Dialogs, OleServer, office2000, StdCtrls, MSPpt2000, ExtCtrls;type TForm1 = class(TForm) Memo1: TMemo; OpenDialog1: TOpenDialog; PowerPointApplication1: TPowerPointApplication; Panel1: TPanel; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var PPT, PP: Variant; i,j:integer; s:string;begin if opendialog1.Execute then begin PPT := CreateOleObject('PowerPoint.Application') ; PPT.visible:=msoTrue; pp := ppt.Presentations.Open(opendialog1.FileName,msoFalse,msoFalse, msoTrue); for I := 1 to pp.Slides.Count do for J := 1 to pp.Slides.Item(I).Shapes.Count do if pp.Slides.Item(I).Shapes.Item(J).TextFrame.HasText then S := S + #13#10 + pp.Slides.Item(I).Shapes.Item(J).TextFrame.TextRange.Text; Memo1.Text := S; PPT.Quit; PP := UnAssigned; PPT := UnAssigned; end;end;procedure TForm1.Button2Click(Sender: TObject);var pptA: TPowerPointApplication; pptP: TPowerPointPresentation; ssSet: SlideShowSettings; ssWin: SlideShowWindow;begin if opendialog1.Execute then begin try pptA := TPowerPointApplication.Create(self); pptP := TPowerPointPresentation.Create(Self); pptA.Visible := msoTrue; PPtP.ConnectTo(pptA.Presentations.Open(opendialog1.FileName, msoFalse, msoFalse, msoTrue)); ssSet := PPtP.SlideShowSettings; ssSet.LoopUntilStopped := msoFalse; ssSet.ShowType := ppShowTypeSpeaker; ssSet.Run; ssWin := PPtP.SlideShowWindow; finally pptA.Free; pptP.Free; end; end;end;end.
 
与office的版本有关!如果用ole技术就与office版本无关了,查用ole操控ppt的代码。
 
office的版本有关那用那个版本的就没问题呢?ole怎么做?
 
如果你机器装的是2007 用现有的ole是不能够操作的,office2007和原来的office2000,office2003的存储的格式是完全不一样的,建议你换成office2003
 
把这句代码拿掉。。 pptA.Visible := msoTrue;
 
后退
顶部