How to use Zorder.....in my Coding?

G

Guest

Hi
I am doing Simulation in powerpoint using Visaul Basic...... i am apllying
the code for zorder but its now working properly.
Means wht i want is i want to set zoder,means if some one add picture to the
slide then i shld make its order as 1 then when rectangles come then the
zorder for them is 1,then i want to set the order of text as 1.why i want
this is bcos if some one add picture to it first it shld show picture then on
the picture it shld show rectangles with the text.......

If any one know the procedure how to do it plz help me.i am attaching the
code for it which i am using...

Public Sub Set_ZOrder()
On Error Resume Next
Dim Counter As Long, i As Long
For Each sld In App_.ActivePresentation.Slides
ReDim Shapes_(sld.Shapes.Count)
Counter = 0
For Each shp In sld.Shapes
shp.ZOrder msoSendToBack
Next
For Each shp In sld.Shapes
If InStr(shp.Name, "CustRec") > 0 Then
shp.ZOrder msoSendBehindText 'msoBringToFront
End If
Next
For Each shp In sld.Shapes
If InStr(shp.Name, "CustText") > 0 Then
shp.ZOrder msoBringToFront
End If
Next
Next
End Sub

i am trying this but some time rectangle come on the picture some time even
rectangle with text r comin on picture....

Currently i am doing my coding in Visual Basic .
Thanks
Amrish
 
S

Steve Rindsberg

HelpSeeker said:
Hi
I am doing Simulation in powerpoint using Visaul Basic...... i am apllying
the code for zorder but its now working properly.
Means wht i want is i want to set zoder,means if some one add picture to the
slide then i shld make its order as 1 then when rectangles come then the
zorder for them is 1,then i want to set the order of text as 1.why i want
this is bcos if some one add picture to it first it shld show picture then on
the picture it shld show rectangles with the text.......

If any one know the procedure how to do it plz help me.i am attaching the
code for it which i am using...

Some comments:

It seems you don't use or need the variables Counter or i
I deleted them
Likewise Shapes_
Public Sub Set_ZOrder()
On Error Resume Next
For Each sld In App_.ActivePresentation.Slides

This will reverse the order of all shapes on the slide.
If that's what you need to do, fine. But do you need to do it?
For Each shp In sld.Shapes
shp.ZOrder msoSendToBack
Next

msoSendBehindText only applies to MS Word even though it appears in the object
model for PPT.
For Each shp In sld.Shapes
If InStr(shp.Name, "CustRec") > 0 Then
shp.ZOrder msoSendBehindText 'msoBringToFront
End If
Next
For Each shp In sld.Shapes
If InStr(shp.Name, "CustText") > 0 Then
shp.ZOrder msoBringToFront
End If
Next
Next
End Sub

What are the shapes "CustRec" and "CustText"? Which is the picture and which is
the rectangle? I can't quite understand what you want to end up with, but I'm
sure there's a way to solve the problem.

Have another try at explaining?
 
G

Guest

Hi,
Yes steve u r right i am not using counter & i any where.... it would not
effect my code... I have done a coding that I can animate text on the slide
along with the rectangle. but while testing i have placed a shape(i.e. Oval)
on the slide, then the rectangle & text r coming behind that paricular shape,
so i have used the concept of Zorder.... But now when i am using this Zoder
Concept then some rectangles r coming on the shape (i.e Oval ) some r coming
behind the Shape(i.e Oval).
So What i want if some one add shape to the slide then shape Zoder shld
become 1 & after that it shld be send to back so that when the rectangle
comes then its zorder shld become 1 & send to back & then when the text come
its Zorder shld become 1.

This CustRect is the name of each rectangle we r giving in our coding i.e
CustRect1,CusrtRect2... in the given slide.

If InStr(shp.Name, "CustRec") > 0 Then
shp.ZOrder msoSendBehindText

"When the name of the currently considered shape is CustRec, make the
Zorder=1 & send to back"

This CustText is the name of each rectangle we r giving in our coding i.e
Custtext1,CustText2...... in the given slide.

So, I would say that plese don;t worry about the custrec and custtext. These
are just names of the shapes (for our reference) that wea r adding on
theslide. Actually, these are the shapes whom we want to come in front. The
order is that the custtext should come on the front, then custrec should come
behind it and then whatver other shape is there. So thats why I m making the
Zorder of all the shapes to msobringtofront. Then i set the zorder of custrec
to msobringtofront and then finally the zorder of custtext to
msobringtofront. BUt its not working.

Thanks for the help.
Amrish
 
S

Steve Rindsberg

Hi,
Yes steve u r right i am not using counter & i any where.... it would not
effect my code... I have done a coding that I can animate text on the slide
along with the rectangle. but while testing i have placed a shape(i.e. Oval)
on the slide, then the rectangle & text r coming behind that paricular shape,
so i have used the concept of Zorder.... But now when i am using this Zoder
Concept then some rectangles r coming on the shape (i.e Oval ) some r coming
behind the Shape(i.e Oval).

Let's see if we can simplify this.

When you add a new shape, can you also get a reference to the shape you want it to be
just in front of or behind?

If so, it's fairly simple to control the relative order.


Sub InFrontOf(oTopShape As Shape, oBottomShape As Shape)

While oBottomShape.ZOrderPosition < oTopShape.ZOrderPosition
oTopShape.ZOrder msoSendBackward
Wend

End Sub

Sub testit()
' assumes a slide with shapes named Back and Front
' puts Back in front of Front w/o changing order
' of other shapes
With ActivePresentation.Slides(1)
Call InFrontOf(.Shapes("Back"), .Shapes("Front"))
End With
End Sub
 

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