Consulting

Results 1 to 17 of 17

Thread: for and Slides

  1. #1
    VBAX Regular
    Joined
    Nov 2013
    Posts
    11
    Location

    for and Slides

    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

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Regular
    Joined
    Nov 2013
    Posts
    11
    Location
    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 ?

  4. #4
    VBAX Regular
    Joined
    Nov 2013
    Posts
    11
    Location
    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

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    VBAX Regular
    Joined
    Nov 2013
    Posts
    11
    Location
    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 !

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    VBAX Regular
    Joined
    Nov 2013
    Posts
    11
    Location
    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 -_-

  9. #9
    VBAX Regular
    Joined
    Nov 2013
    Posts
    11
    Location
    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

  10. #10
    VBAX Regular
    Joined
    Nov 2013
    Posts
    11
    Location
    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

  11. #11
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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/show...ght=subaddress
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  12. #12
    VBAX Regular
    Joined
    Nov 2013
    Posts
    11
    Location
    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.

  13. #13
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  14. #14
    VBAX Regular
    Joined
    Nov 2013
    Posts
    11
    Location
    So vba isn't such a bad language sometimes

    if you need some help, I am here

  15. #15
    VBAX Regular
    Joined
    Nov 2013
    Posts
    11
    Location
    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

  16. #16
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  17. #17
    VBAX Regular
    Joined
    Nov 2013
    Posts
    11
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •