Reading title text fro a slide

G

Guest

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?
 
G

Guest

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
 
S

Steve Rindsberg

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?

If it's what I think it is, you can't; you'll have to trap it and work around
it. Some versions of PPT will allow you to drag a picture INTO a text
placeholder. That leaves you with a textbox shape that reports that it has a
text frame but won't allow you to touch it w/o erroring.
 
S

Steve Rindsberg

Shyam Pillai said:
Definitely one from the old days. :)

There's no bug like a legacy bug.
Quick, get out the big can of Deprecate and spray it real good.
 
G

Guest

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?
 
S

Steve Rindsberg

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?


No, but can you post a sample presentation on the web where we can download it?
One slide should be enough, just enough to cause the error.
 
S

Steve Rindsberg

Sorry,

first read than ask, here the link: http://www.bevsh.de/seite3.htm

;-)

I downloaded your presentation and ran this on it in PPT2003; no problems at
all. Give this a try on your computer and let us know what happens:

Sub Test()

Dim oSh As Shape

For Each oSh In ActivePresentation.Slides(1).Shapes
Debug.Print oSh.Name
If oSh.Type = msoGroup Then
Debug.Print vbTab _
& "Group with shapecount: " _
& CStr(oSh.GroupItems.Count)
End If

Next

End Sub
 
G

Guest

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

Steve Rindsberg

Hi Steve,

first I have to say that I use Delphi7 to control PowerPoint.

We won't hold that against you. ;-)
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".

I'm not clear on something: does it do this running your code or the code
snippet I posted (or both?)

What if you substitute

MsgBox oSh.Name
MsgBox oSh.Type

(or the delphic equivalent)
Unfortunately I cannot post the file because it contains confidential data.

That's sometimes the way it is. No problem.
 
G

Guest

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
 
S

Steve Rindsberg

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

Odd.

I've never used Delphi but there are a few here who do. And I used to speak
tourist-grade Pascal so if you could post a bit of the relevant code here, it
might be worthwhile.
 
G

Guest

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;
 
S

Steve Rindsberg

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;

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;
 
G

Guest

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
================================================
 
S

Steve Rindsberg

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.

True but not the point ... first, you may want to determine whether the problem
IS a corrupt object or something to do with your code. My suggestions will help
with that, I think.

If it's a corrupt object ... well, corrupt objects happen ... that's a fact of
life that we simply have to deal with. You'll want to trap any errors and deal
with them in your code, ideally.
 

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