Aqueath
asked on
Powerpoint Automation
Hi,
I'm trying to open an existing powerpoint file, and change the values within a datasheet in one of the slides. Anyone got a working sample of code that does this? Ie
-Open an instance of powerpoint in the background
-Open an existing ppt file
-Change the values within a graphs datasheet.
-Add some text somewhere
-Save the file, and close pp.
A.
I'm trying to open an existing powerpoint file, and change the values within a datasheet in one of the slides. Anyone got a working sample of code that does this? Ie
-Open an instance of powerpoint in the background
-Open an existing ppt file
-Change the values within a graphs datasheet.
-Add some text somewhere
-Save the file, and close pp.
A.
If you're not up to it, post a sample presentation that we can muck with...
ASKER
Ok, a sample presentation? Open PP.
-Select New->The New slide window opens
-Select graph
-Doubleclick the graph->you get a sample graph with datasheet.
-Save as...
And you have a sample presentation to muck with...
-Select New->The New slide window opens
-Select graph
-Doubleclick the graph->you get a sample graph with datasheet.
-Save as...
And you have a sample presentation to muck with...
Using PP2002 so it is different.
ASKER
Hi Eddie,
Found an example for you. It can be downloaded from:
http://portfolio.educ.kent.edu/studentj/equity.ppt
On slide 6 there is a graph.
Hope to hear from you soon.
A.
Found an example for you. It can be downloaded from:
http://portfolio.educ.kent.edu/studentj/equity.ppt
On slide 6 there is a graph.
Hope to hear from you soon.
A.
ASKER
In VB this would look something like ;
Private pp As PowerPoint.Application
Private pr As PowerPoint.Presentation
Private ds As Graph.DataSheet
Set pp = CreateObject("PowerPoint.A pplication ")
Set pr = pp.Presentations.Open('d:\ equity.ppt ')
Set ds = pr.Slides(6).Shapes(2).OLE Format.Obj ect.Applic ation.Data Sheet //This line I need converted from VB to Delphi
ds.Cells(1, 3) = "Test"
ds.Cells(2, 3) = 22
ds.Cells(3, 3) = 3
ds.Cells(4, 3) = 72
ds.Application.Update
In Delphi so far I have:
uses ComObj;
...
procedure TForm1.Button1Click(Sender : TObject);
var
pp : Variant;
pr : Variant;
ds : Variant; //do I need some other declaration?
begin
try
pp:=GetActiveOleObject('Po werPoint.A pplication ');
except
pp:=CreateOleObject('Power Point.Appl ication');
end;
pp.Visible := True; //I can't seem to get the next line of code to work without visible set to true.
pr:=pp.Presentations.Open( 'd:\equity .ppt'); //File can be downloaded from the link in the previous comment
ds:=pr.Slides.item(6).shap es.item(2) .OleFormat ; //This is where I'm currently stuck converting from VB.
...
//ds.Application.Update; //?
end;
I'm no good in VB, so could someone tell me how to convert the line...
Set ds = pr.Slides(6).Shapes(2).OLE Format.Obj ect.Applic ation.Data Sheet
...from VB to delphi? I have so far
ds:=pr.Slides.item(6).shap es.item(2) .OleFormat ;
Anyone?
A.
Private pp As PowerPoint.Application
Private pr As PowerPoint.Presentation
Private ds As Graph.DataSheet
Set pp = CreateObject("PowerPoint.A
Set pr = pp.Presentations.Open('d:\
Set ds = pr.Slides(6).Shapes(2).OLE
ds.Cells(1, 3) = "Test"
ds.Cells(2, 3) = 22
ds.Cells(3, 3) = 3
ds.Cells(4, 3) = 72
ds.Application.Update
In Delphi so far I have:
uses ComObj;
...
procedure TForm1.Button1Click(Sender
var
pp : Variant;
pr : Variant;
ds : Variant; //do I need some other declaration?
begin
try
pp:=GetActiveOleObject('Po
except
pp:=CreateOleObject('Power
end;
pp.Visible := True; //I can't seem to get the next line of code to work without visible set to true.
pr:=pp.Presentations.Open(
ds:=pr.Slides.item(6).shap
...
//ds.Application.Update; //?
end;
I'm no good in VB, so could someone tell me how to convert the line...
Set ds = pr.Slides(6).Shapes(2).OLE
...from VB to delphi? I have so far
ds:=pr.Slides.item(6).shap
Anyone?
A.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
Your code so helped me in the right direction. Even made it work without the TLBs as well....Points!!!
Working example code
procedure TForm1.Button1Click(Sender : TObject);
var
pp : OleVariant;
pr : OleVariant;
ds : OleVariant;
qs : OleVariant;
begin
try
pp:=GetActiveOleObject('Po werPoint.A pplication ');
except
pp:=CreateOleObject('Power Point.Appl ication');
end;
pp.Activate;
pr:=pp.Presentations.Open( 'd:\equity .ppt');
ds:=pr.Slides.Item(6).Shap es.Item(2) .OleFormat .object;
qs:=ds.Application.Datashe et;
qs.cells.item[2,2]:='Blue' ;
end;
Would you also know how to run PP in the background? If I never set pp to visible I keep getting this error ;
"The powerpoint frame window does not exist."
A.
Your code so helped me in the right direction. Even made it work without the TLBs as well....Points!!!
Working example code
procedure TForm1.Button1Click(Sender
var
pp : OleVariant;
pr : OleVariant;
ds : OleVariant;
qs : OleVariant;
begin
try
pp:=GetActiveOleObject('Po
except
pp:=CreateOleObject('Power
end;
pp.Activate;
pr:=pp.Presentations.Open(
ds:=pr.Slides.Item(6).Shap
qs:=ds.Application.Datashe
qs.cells.item[2,2]:='Blue'
end;
Would you also know how to run PP in the background? If I never set pp to visible I keep getting this error ;
"The powerpoint frame window does not exist."
A.
http://www.djpate.freeserve.co.uk/AutoPpt.htm
Then just convert the VBA macro source to Delphi.