PDA

View Full Version : for and Slides



nsr88
11-06-2013, 05:54 AM
Hello,

I am using a "for" loop on my sildes. But i guess the "for" is bloquing the numbering. I let you watch :

nbrTitre = 0

For j = 3 To Pres.Slides.Count
If ((Pres.Slides(j).Shapes(1).Width = 648) And (Pres.Slides(j).Shapes(1).Height = 90)) Then
nbrTitre = nbrTitre + 1
End If
Next j

The condition is true only when the slide is empty which is not normal.

Thank you for watching

John Wilson
11-06-2013, 06:16 AM
If the slide was empty (blank) then your code would error as Shape(1) does not exist.

If you have On Error Resume Next somewhere in the code then it would just go to the next line and increment the counter


Sub countme()
Dim j As Long
Dim nbrTitre As Integer
Dim Pres As Presentation
Set Pres = ActivePresentation
nbrTitre = 0

For j = 3 To Pres.Slides.Count
If Pres.Slides(j).Shapes.Count > 0 Then
If ((Pres.Slides(j).Shapes(1).Width = 648) And (Pres.Slides(j).Shapes(1).Height = 90)) Then
nbrTitre = nbrTitre + 1
End If
End If
Next j
MsgBox nbrTitre
End Sub

If you are trying to check whether the slide has a Title Placeholder you can do this with


if Pres.Slides(j).Shapes.HasTitle

nsr88
11-06-2013, 06:24 AM
that's right i have On Error Resume Next
But, the condition never works even if I create one shape with this size : Set shpTitre = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, 36, 21.62504, 648, 90)
Maybe you want to see my whole code ?

nsr88
11-06-2013, 06:53 AM
ok, i understood my problem
When i create a textbox and when i choose the height, the height will not be what i want. here it's 60,58591 and not 90.
Ok problem solved !
thank you

John Wilson
11-06-2013, 07:25 AM
Yes by default textboxes resize to fit the text so you cannot rely on the size. Do you know how to use tags to identfy shapes? That is usually the best way.

nsr88
11-06-2013, 07:40 AM
I started to learn vba PowerPoint today. So I guess I don't know :)
I use the order of creation for knowing the number. If you have something better I'm earing you !

John Wilson
11-06-2013, 08:08 AM
OK

If you add you shape like this:


Sub addTitre()
Dim sld As Slide
Dim shpTitre As Shape
On Error Resume Next
Set sld = ActiveWindow.View.Slide
If Not sld Is Nothing Then
Set shpTitre = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, 36, 21.62504, 648, 90)
shpTitre.Tags.Add "TYPE", "TITRE"
End If
End Sub

The added shape will have an invisible tag

You can check for the shape on any slide using a function:


Function IsTitre(sld As Slide) As Boolean
Dim oshp As Shape
For Each oshp In sld.Shapes
If oshp.Tags("TYPE") = "TITRE" Then
IsTitre = True
Exit For
End If
Next oshp
End Function

To check whether titre is present on a particular slide

Msgbox IsTitre(sld) 'where sld is a reference to the slide

nsr88
11-06-2013, 08:16 AM
Nice ! I will use it.
Is the type Title a default for the title box of these slide PpSlideLayout.ppLayoutTitle ?

I have an other question,
How can I tranform a part of the text in one of my textboxes on hyperlink. I guess it's a newbie question but there's no macro recorder -_-

nsr88
11-06-2013, 08:27 AM
I want to add a hyperlink to this : tdm.Paragraphs.InsertAfter (Pres.Slides(j).Shapes(1).TextFrame.TextRange.Text & Chr(13))
But, when I add Hyperlink.subAdress = j
I got a compilation problem.

tdm is a textRange

nsr88
11-06-2013, 08:34 AM
finally I found for the hyperlink,
tdm.Paragraphs.InsertAfter(Pres.Slides(j).Shapes(1).TextFrame.TextRange.Tex t & Chr(13)).ActionSettings(ppMouseClick).Hyperlink.SubAddress = j

John Wilson
11-06-2013, 09:01 AM
The SubAddress can never be j though

It's a string in the format "SlideID,SlideIndex,Slide Title"

Example would be Hyperlink.SubAddress="256,2,My Title"

I posted some code here
http://www.vbaexpress.com/forum/showthread.php?47962-How-can-you-name-a-slide-and-then-refer-to-it-by-name-in-a-hyperlink&highlight=subaddress

nsr88
11-07-2013, 01:54 AM
I guess, Microsoft made the string optional because it is working on my computers with PPT 2010 and PPT 2013
But thank you for this ! You are very helpful.

John Wilson
11-07-2013, 03:28 AM
Interesting, I would have sworn that wouldn't work.

If you check what the subaddress actually is you will see the PPT has auto filled in the missing digits for you.

nsr88
11-07-2013, 03:41 AM
So vba isn't such a bad language sometimes ;)

if you need some help, I am here :p

nsr88
11-07-2013, 05:20 AM
I noticed something else interesting,

If you create an hyperlink toward a paragraph like i did

and after you change the number of the diapo targeted without changing the hyperlinkn, nothing changed

You will be redirect to the good diapo :)

John Wilson
11-07-2013, 05:51 AM
That's why the sub address has to be based on the SlideID which doesn't change. The slide index and title are usually ignored unless there's a problem with the ID

nsr88
11-07-2013, 06:13 AM
Thanks to you, i just finished my macro for doing a summury with several pages and hyperlinks. If you are interested in I can send it to you. It will be my way to be thankfull ;)