PDA

View Full Version : [SOLVED:] First question - how do I extend this this to a set of slides?



bujay
06-16-2023, 03:26 PM
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!

Paul_Hossler
06-16-2023, 04:21 PM
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

bujay
06-16-2023, 05:56 PM
Thank you!!! This is great and I can go from here. Appreciate it!

Paul_Hossler
06-16-2023, 06:11 PM
No problem

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

(we try to keep things tidy :yes )