Reading title text fro a slide

P

PeterS

Hi,

for me it looks like a bug in ppt 2003:
I scan by program code through the slides of a presentation and want to read
the titles.
1) I check for activepresentation.slides.item(counter).shapes.hastitel =
msotrue
2) than for
activepresentation.slides.item(counter).shapes.titel.textframe.hastext =
msotrue
3) try to read from
activepresentation.slides.item(counter).shapes.title.textframe.textrange.text

In one case I get an error message "this type of object cannot have a
textrange". The object looks like a picture object.

How can I prevent this error?
 
J

John Wilson

Try something along these lines instead

Sub readtitle()
Dim osld As Slide, oshp As Shape
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.Type = msoPlaceholder Then
If oshp.PlaceholderFormat.Type = ppPlaceholderCenterTitle _
Or ppPlaceholderTitle Then
If oshp.TextFrame.HasText Then _
MsgBox oshp.TextFrame.TextRange.Text
End If
End If
Next
Next
End Sub
 
P

PeterS

Thank you for the discussion. Meanwhile I ran in the next trouble:

I check "shapes.item(No).type = msogroup"

in some/few ppt presentations the next statement

"shapes.item(No).groupitems.count"

create a error again

I have no idea why, do you have?
 
P

PeterS

Hi Steve,

first I have to say that I use Delphi7 to control PowerPoint.
I tried your code snipplet with following result:

a) the slide I put in the internet works fine; now it works also fine in my
program
b) the original file still shows a error message; It creates an exception
when I call "oSh.GroupItems.Count". The error message is "shape (unknown
member): invalid request. presentation cannot be modified".

Unfortunately I cannot post the file because it contains confidential data.
 
P

PeterS

Hi,

I have fully access to any property of the shape object except the
groupitems property.

osh.name = group5
osh.type = grouped or the respective constant
osh.groupitems creates an exception
 
P

PeterS

Here the complete code of the analysing part of the program. It reads from
Powerpoint file and shows the information in a tree (Fullview).
PI, SI, HI are classes to store specific information of Presentation, Slide
and Shape.

Most of the rest is VBA in Delphi dialect.


FullView.Items.Clear;
FirstNode:=FullView.Items.AddFirst(NIL,DM_DB.T_ppt['FileName']);
AktPres:=FirstNode;
for PresCnt:=1 to PptApp.Presentations.Count do
begin
PI:=TPresentationInfo.create;
PI.FullName:=PptApp.Presentations.item(PresCnt).FullName;
if PresCnt = 1 then
AktPres:=FullView.Items.AddChildObject(AktPres,PI.FullName,PI)
else
AktPres:=FullView.Items.AddObject(AktPres,PI.FullName,PI);
AktSlide:=AktPres;
for SldCnt:=1 to PptApp.Presentations.item(PresCnt).Slides.Count do
begin

PptSlide.ConnectTo(PptApp.Presentations.item(PresCnt).Slides.Item(SldCnt));
SI:=TSlideInfo.Create;
SI.SlideIndex:=PptSlide.SlideIndex;
SI.Name:=PptSlide.Name;
if PptSlide.Shapes.HasTitle = msoTrue then
SI.Titel:=PptSlide.Shapes.Title.TextFrame.TextRange.Text;
if SldCnt = 1 then

AktSlide:=FullView.Items.AddChildObject(AktSlide,PptSlide.Name,SI)
else
AktSlide:=FullView.Items.AddObject(AktSlide,PptSlide.Name,SI);
AktShape:=AktSlide;
if PptSlide.Shapes.HasTitle = msotrue then

AktShape:=FullView.Items.AddChild(AktShape,PptSlide.Shapes.Title.TextFrame.TextRange.Text)
else
AktShape:=FullView.Items.AddChild(AktShape,'Kein Titel');
for shpCnt:=1 to PptSlide.Shapes.Count do
begin
HI:=TShapeInfo.Create;
HI.Name:=PptSlide.Shapes.item(shpCnt).Name;
HI.ShapeTyp:=PptSlide.Shapes.item(shpCnt).type_;
HI.TypName:='';
if PptSlide.Shapes.item(shpCnt).HasTextFrame = msoTrue then

HI.Text:=PptSlide.Shapes.item(shpCnt).TextFrame.TextRange.Text
else
HI.Text:='';

AktShape:=FullView.Items.AddObject(AktShape,PptSlide.Shapes.item(shpCnt).Name,HI);
if PptSlide.Shapes.Item(shpCnt).type_ = msoGroup then
begin
AktGrp:=AktShape;

for grpCnt:=1 to
PptSlide.Shapes.item(shpCnt).GroupItems.Count do
begin
HI:=TShapeInfo.Create;

HI.Name:=PptSlide.Shapes.item(shpCnt).GroupItems.item(grpCnt).Name;

HI.ShapeTyp:=PptSlide.Shapes.item(shpCnt).GroupItems.item(grpCnt).type_;
HI.TypName:='';
if
PptSlide.Shapes.item(shpCnt).GroupItems.Item(grpCnt).HasTextFrame = msoTrue
then

HI.Text:=PptSlide.Shapes.item(shpCnt).GroupItems.item(grpCnt).TextFrame.TextRange.Text
else
HI.Text:='';
if grpCnt = 1 then

AktGrp:=FullView.Items.AddChildObject(AktGrp,PptSlide.Shapes.item(shpCnt).GroupItems.item(grpCnt).Name,HI)
else

AktGrp:=FullView.Items.AddObject(AktGrp,PptSlide.Shapes.item(shpCnt).GroupItems.item(grpCnt).Name,HI);
end;
end;
end;
end;
end;
 
P

PeterS

Hi Steve,

thank you for your effort, but to repair the slide is not my problem. I'm
writing a program to analyse the content of powerpoint files and certain
slides contain some let's say corrupted objects. I'm not able to handle these
corrupt objects, my program will run into an error condition. I see no chance
to circumvent this situation. For me is that a poor programming style and the
source is outside my scope, thank you Microsoft.

--
Thank you very much

PeterS


Steve Rindsberg said:
Here the complete code of the analysing part of the program. It reads from
Powerpoint file and shows the information in a tree (Fullview).
PI, SI, HI are classes to store specific information of Presentation, Slide
and Shape.

Thanks ... it's easy enough to follow, with that introduction.

It certainly seems ok to me (though someone more familiar with automating PPT from Delphi might see
something I'm missing).

Since this doesn't happen on all slides, just some (one?) I wonder if you have a corrupt object.
Try making a copy of the slide then ungroup the problem group and immediately re-group it again.

If that doesn't help, round-trip the presentation to HTML and back.
HTML "Round-tripping" to repair corruption
http://www.pptfaq.com/FAQ00526.htm

(I know, it sounds like a fairy tale, but it does work sometimes. Really.)
Most of the rest is VBA in Delphi dialect.

FullView.Items.Clear;
FirstNode:=FullView.Items.AddFirst(NIL,DM_DB.T_ppt['FileName']);
AktPres:=FirstNode;
for PresCnt:=1 to PptApp.Presentations.Count do
begin
PI:=TPresentationInfo.create;
PI.FullName:=PptApp.Presentations.item(PresCnt).FullName;
if PresCnt = 1 then
AktPres:=FullView.Items.AddChildObject(AktPres,PI.FullName,PI)
else
AktPres:=FullView.Items.AddObject(AktPres,PI.FullName,PI);
AktSlide:=AktPres;
for SldCnt:=1 to PptApp.Presentations.item(PresCnt).Slides.Count do
begin

PptSlide.ConnectTo(PptApp.Presentations.item(PresCnt).Slides.Item(SldCnt));
SI:=TSlideInfo.Create;
SI.SlideIndex:=PptSlide.SlideIndex;
SI.Name:=PptSlide.Name;
if PptSlide.Shapes.HasTitle = msoTrue then
SI.Titel:=PptSlide.Shapes.Title.TextFrame.TextRange.Text;
if SldCnt = 1 then

AktSlide:=FullView.Items.AddChildObject(AktSlide,PptSlide.Name,SI)
else
AktSlide:=FullView.Items.AddObject(AktSlide,PptSlide.Name,SI);
AktShape:=AktSlide;
if PptSlide.Shapes.HasTitle = msotrue then

AktShape:=FullView.Items.AddChild(AktShape,PptSlide.Shapes.Title.TextFrame.TextRange.Text)
else
AktShape:=FullView.Items.AddChild(AktShape,'Kein Titel');
for shpCnt:=1 to PptSlide.Shapes.Count do
begin
HI:=TShapeInfo.Create;
HI.Name:=PptSlide.Shapes.item(shpCnt).Name;
HI.ShapeTyp:=PptSlide.Shapes.item(shpCnt).type_;
HI.TypName:='';
if PptSlide.Shapes.item(shpCnt).HasTextFrame = msoTrue then

HI.Text:=PptSlide.Shapes.item(shpCnt).TextFrame.TextRange.Text
else
HI.Text:='';

AktShape:=FullView.Items.AddObject(AktShape,PptSlide.Shapes.item(shpCnt).Name,HI);
if PptSlide.Shapes.Item(shpCnt).type_ = msoGroup then
begin
AktGrp:=AktShape;
Next line raises the exception when it comes to the specific slide

for grpCnt:=1 to
PptSlide.Shapes.item(shpCnt).GroupItems.Count do
begin
HI:=TShapeInfo.Create;

HI.Name:=PptSlide.Shapes.item(shpCnt).GroupItems.item(grpCnt).Name;

HI.ShapeTyp:=PptSlide.Shapes.item(shpCnt).GroupItems.item(grpCnt).type_;
HI.TypName:='';
if
PptSlide.Shapes.item(shpCnt).GroupItems.Item(grpCnt).HasTextFrame = msoTrue
then

HI.Text:=PptSlide.Shapes.item(shpCnt).GroupItems.item(grpCnt).TextFrame.TextRange.Text
else
HI.Text:='';
if grpCnt = 1 then

AktGrp:=FullView.Items.AddChildObject(AktGrp,PptSlide.Shapes.item(shpCnt).GroupItems.item(grpCnt).Name,HI)
else

AktGrp:=FullView.Items.AddObject(AktGrp,PptSlide.Shapes.item(shpCnt).GroupItems.item(grpCnt).Name,HI);
end;
end;
end;
end;
end;

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top