Consulting

Results 1 to 4 of 4

Thread: First question - how do I extend this this to a set of slides?

  1. #1
    VBAX Newbie
    Joined
    Jun 2023
    Posts
    2
    Location

    First question - how do I extend this this to a set of slides?

    The VBA below does exactly what I want it to do but as you can see, it only works on Slide 14 in its current form....

    Is there a way I could create a loop so that I can list the slides I want this to apply to?

    For example, how would I adjust the macro below to apply to slides 13, 14, 15, 16, 18, 19, 20, 25, 27, etc....perhaps I could write an array for the slide numbers...


    Function getshape1() As Shape
        Set getshape1 = ActivePresentation.Slides(14).Shapes(5)
    End Function
    
    Function getshape2() As Shape
        Set getshape2 = ActivePresentation.Slides(14).Shapes(6)
    End Function
    
    Function getshape3() As Shape
        Set getshape3 = ActivePresentation.Slides(14).Shapes(7)
    End Function
    
    Function getshape4() As Shape
        Set getshape4 = ActivePresentation.Slides(14).Shapes(8)
    End Function
    
    
    Sub move_shapes()
    Set sh1 = getshape1
        Set sh2 = getshape2
        Set sh3 = getshape3
        Set sh4 = getshape4
    sh1.Top = 80
        sh1.Left = 35
    sh2.Top = 80
        sh2.Left = 488
    sh3.Top = 297
        sh3.Left = 35
    sh4.Top = 297
        sh4.Left = 488
    End Sub
    Thanks!

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,693
    Location
    Not tested

    BTW, personally, I don't like to hard code so many things (slide numbers, shape numbers)

    If there were a way to programmatically determine a slide and a shape it'd be better


    Option Explicit
    
    
    Sub DoSlides()
        Dim i As Variant, j As Variant
        For Each i In Array(13, 14, 15, 16, 18, 19, 20, 25, 27)
            For Each j In Array(5, 6, 7, 8)
                With ActivePresentation.Slides(i).Shapes(j)
                    Select Case j
                        Case 5
                            .Top = 80
                            .Left = 35
                        Case 6
                            .Top = 80
                            .Left = 488
                        Case 7
                            .Top = 297
                            .Left = 35
                        Case 8
                            .Top = 297
                            .Left = 400
                    End Select
                End With
            Next j
        Next i
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Newbie
    Joined
    Jun 2023
    Posts
    2
    Location
    Thank you!!! This is great and I can go from here. Appreciate it!

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,693
    Location
    No problem

    You can mark the thread [SOLVED] using [Thread Tools] button above your first post

    (we try to keep things tidy )
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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