Yogaraj Deenadayalan
asked on
Aligning 5 picture in powerpoint VBA
I want to align 5 pictures in a slide like 1 picture at center and 4 picture at four corners.
I can able to create a macro to align picture one by one.
But I need to align all 5 picture at once.
This is the code I used to align 1 picture
Sub BildZ()
With ActiveWindow.Selection.Sha peRange
.Height = 130.05
.Width = 215.05
.Left = 250.12
.Top = 225.12
ActiveWindow.Selection.Sha peRange.ZO rder msoSendToBack
End With
End Sub
Thanks in advance
I can able to create a macro to align picture one by one.
But I need to align all 5 picture at once.
This is the code I used to align 1 picture
Sub BildZ()
With ActiveWindow.Selection.Sha
.Height = 130.05
.Width = 215.05
.Left = 250.12
.Top = 225.12
ActiveWindow.Selection.Sha
End With
End Sub
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is there any possibility to ask the user to select the image while macro is running.
For example macro should ask the used select image to be placed on top right followed by other position
For example macro should ask the used select image to be placed on top right followed by other position
That's much more complex because what you need to do is handle application level events in PowerPoint in order to be able to detect when the user is modifying the selection. It's possible but not trivial.
Thanks for the Accepted Solution Yogaraj. Here's an alternative simpler method (without using application event handlers) of making guiding the user to make the selection in sequence.
Add this to a Standard Module:
Add this to a UserForm named "UserForm1":
Back in PowerPoint, press Alt+F8 and run the macro AlignPictures.
When running the new AlignPictures macro, this will initially present itself as follows:
On each press of the button, the button instruction changes to indicate which picture to select next until all 5 pictures have been selected and aligned.
There is no error condition checking for wrong selections in this example.
Add this to a Standard Module:
Sub AlignPictures()
UserForm1.Show
End Sub
Add this to a UserForm named "UserForm1":
Option Explicit
' Instructions
' Insert a UserForm named UserForm1 and set the form's Width to 24, Height to 90, ShowModal to False
' Add a single button to the UserForm named CommandButton1 and set its Width to 192
' Add the code below to the UserForm
' Add the commented out sub AlignPictures below (without comment marks) to a standard module and run it from PowerPoint with Alt+F8
'Sub AlignPictures()
' UserForm1.Show
'End Sub
Private counter As Long
Private Sub UserForm_Initialize()
counter = 0
CommandButton1.Caption = "Select TOP LEFT shape and press this button"
End Sub
Private Sub CommandButton1_Click()
Dim SlideX As Single
Dim SlideY As Single
counter = counter + 1
With ActivePresentation.PageSetup
SlideX = .SlideWidth
SlideY = .SlideHeight
End With
With ActiveWindow.Selection.ShapeRange(1)
Select Case counter
Case 1
.Left = 0
.Top = 0
CommandButton1.Caption = "Select TOP RIGHT shape and press this button"
Case 2
.Left = SlideX - .Width
.Top = 0
CommandButton1.Caption = "Select BOTTOM LEFT shape and press this button"
Case 3
.Left = 0
.Top = SlideY - .Height
CommandButton1.Caption = "Select BOTTOM RIGHT shape and press this button"
Case 4
.Left = SlideX - .Width
.Top = SlideY - .Height
CommandButton1.Caption = "Select CENTRE shape and press this button"
Case 5
.Left = (SlideX - .Width) / 2
.Top = (SlideY - .Height) / 2
Unload Me
Case Else
Unload Me
End Select
End With
End Sub
Back in PowerPoint, press Alt+F8 and run the macro AlignPictures.
When running the new AlignPictures macro, this will initially present itself as follows:
On each press of the button, the button instruction changes to indicate which picture to select next until all 5 pictures have been selected and aligned.
There is no error condition checking for wrong selections in this example.
ASKER