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

Description of your first forum.

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

帖子maozhuxi » 星期日, 2009年2月1日 11:51


PPtP.ConnectTo(pptA.Presentations.Open('D:\my_pro\out_ppt\1.ppt', msoFalse, msoFalse, msoTrue));
我是想打开ppt文件,但是运行到这里就报未知错误。

下面是我的源代码:
button1和button2的用处一样都是想打开ppt,但是就是报错,实在没办法。

unit Unit1;

interface

uses
  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);
var
pptA: TPowerPointApplication;
pptP: TPowerPointPresentation;
ssSet: SlideShowSettings;
ssWin: SlideShowWindow;
begin
pptA := 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.
 
 
 

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

帖子hanyuhen1 » 星期一, 2009年2月2日 10:12


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;
 
 
 

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

帖子maozhuxi » 星期一, 2009年2月2日 22:08


还是同样的报错误

代码按照你说的修改如下:


procedure TForm1.Button2Click(Sender: TObject);
var
pptA: 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;
 
 
 

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

帖子maozhuxi » 星期一, 2009年2月2日 22:10


可以运行
还是在这里报错:
 PPtP.ConnectTo( pptA.Presentations.Open(opendialog1.FileName, msoFalse, msoFalse, msoTrue) );
 
 
 

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

帖子hanyuhen1 » 星期二, 2009年2月3日 10:07


我再次试了下,成功以幻灯片的形式打开了
 
 
 

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

帖子maozhuxi » 星期二, 2009年2月3日 15:40


这是我的全部代码,为什么我的就要报错呢?

unit Unit1;

interface

uses
  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);
var
pptA: 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.
 
 
 

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

帖子dzx2004 » 星期五, 2009年6月19日 10:26


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;  


我这边没问题
 
 
 

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

帖子菜鸟黄 » 星期五, 2009年6月19日 13:43


unit Unit1;

interface

uses
  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.
 
 
 

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

帖子newsmile » 星期一, 2009年6月29日 09:35


与office的版本有关!如果用ole技术就与office版本无关了,查用ole操控ppt的代码。
 
 
 

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

帖子maozhuxi » 星期一, 2009年6月29日 13:13


office的版本有关
那用那个版本的就没问题呢?
ole怎么做?
 
 
 

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

帖子dxiaoliang » 星期一, 2009年6月29日 14:33


如果你机器装的是2007 用现有的ole是不能够操作的,office2007和原来的office2000,office2003的存储的格式是完全不一样的,建议你换成office2003
 
 
 

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

帖子japhe » 星期六, 2009年8月29日 12:57


把这句代码拿掉。。
pptA.Visible := msoTrue;