Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

toggle between different alignments of pictures by means of VBA

Posted on 2012-12-20
5
Medium Priority
?
405 Views
Last Modified: 2012-12-21
Dear Experts:

below macros allow me to align pictures on the slides of the active presentation.
Thank you again to JRS Wilsion for that. Now I would like to tweak that code even more.

The user should be able to press a toggle button to toggle between different alignments.

The first code lets the user align all the pictures on all the slides of the active presentation vertically and horizontally centered

The second code lets the user align the pictures on all the slides of the active presentation horizontally centered but the vertical alignment is '.Top = 180'

The third code lets the user align the pictures on all the slides of the active presentation horizontally centered but the vertical alignment is '.Top = 250'

As a matter of fact, I got no idea how to combine these codes so that repeated pressing of the macro button toogles between these different states of alignment. I hope this is not asking too much.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub ResizeAndPosition_Pictures_ToggleButton_1()
' pictures horizontally and vertically centered

Dim i As Integer
Dim oshp As Shape
Dim oshpR As ShapeRange
For i = 1 To ActivePresentation.Slides.Count
For Each oshp In ActivePresentation.Slides(i).Shapes
If oshp.Type = msoPlaceholder Then
If oshp.PlaceholderFormat.ContainedType = msoPicture Then
oshp.ScaleHeight 0.7, True
Set oshpR = ActivePresentation.Slides(i).Shapes.Range(oshp.ZOrderPosition)
oshpR.Align msoAlignCenters, True
oshpR.Align msoAlignMiddles, True
End If
Else
If oshp.Type = msoPicture Then
oshp.ScaleHeight 0.7, True
Set oshpR = ActivePresentation.Slides(i).Shapes.Range(oshp.ZOrderPosition)
oshpR.Align msoAlignCenters, True
oshpR.Align msoAlignMiddles, True
End If
End If
Next oshp
Next i
End Sub

Open in new window



                                           
Sub ResizeAndPosition_Pictures_ToggleButton_2()
'pictures horizontally centered, .Top Property = 180

Dim i As Integer
Dim oshp As Shape
Dim oshpR As ShapeRange
For i = 1 To ActivePresentation.Slides.Count
For Each oshp In ActivePresentation.Slides(i).Shapes
If oshp.Type = msoPlaceholder Then
If oshp.PlaceholderFormat.ContainedType = msoPicture Then
oshp.ScaleHeight 0.7, True
Set oshpR = ActivePresentation.Slides(i).Shapes.Range(oshp.ZOrderPosition)
oshpR.Align msoAlignCenters, True
oshp.Top = 180
End If
Else
If oshp.Type = msoPicture Then
oshp.ScaleHeight 0.7, True
Set oshpR = ActivePresentation.Slides(i).Shapes.Range(oshp.ZOrderPosition)
oshpR.Align msoAlignCenters, True
oshp.Top = 180
End If
End If
Next oshp
Next i

Open in new window



Sub ResizeAndPosition_Pictures_ToggleButton_3()
'horizontally centered, .Top Property = 250
Dim i As Integer
Dim oshp As Shape
Dim oshpR As ShapeRange
For i = 1 To ActivePresentation.Slides.Count
For Each oshp In ActivePresentation.Slides(i).Shapes
If oshp.Type = msoPlaceholder Then
If oshp.PlaceholderFormat.ContainedType = msoPicture Then
oshp.ScaleHeight 0.7, True
Set oshpR = ActivePresentation.Slides(i).Shapes.Range(oshp.ZOrderPosition)
oshpR.Align msoAlignCenters, True
oshp.Top = 250
End If
Else
If oshp.Type = msoPicture Then
oshp.ScaleHeight 0.7, True
Set oshpR = ActivePresentation.Slides(i).Shapes.Range(oshp.ZOrderPosition)
oshpR.Align msoAlignCenters, True
oshp.Top = 250
End If
End If
Next oshp
Next i

Open in new window

0
Comment
Question by:AndreasHermle
  • 2
  • 2
5 Comments
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 400 total points
ID: 38710238
Hi Andreas,
You can use the caption of a Toggle button to tell what comes next to the user and to the code.
Sub TriToggle_Click()
    Select Case TriToggle.Caption
        Case "Centre"
            ResizeAndPosition_Pictures_ToggleButton_1
            TriToggle.Caption = "180"
        Case "180"
            ResizeAndPosition_Pictures_ToggleButton_2
            TriToggle.Caption = "240"
        Case "240"
            ResizeAndPosition_Pictures_ToggleButton_3
            TriToggle.Caption = "Centre"
    End Select
End Sub

Open in new window

0
 
LVL 23

Assisted Solution

by:JSRWilson
JSRWilson earned 1600 total points
ID: 38710482
I think I'd use a combo box
Demo here
0
 

Author Comment

by:AndreasHermle
ID: 38712170
Dear JSRWilson, dear Graham,

thank you very much for your swift and professional support. Both your solutions are workable and will come in handy in other circumstances.

As a matter of fact I am looking for a solution where all three of the above codes get integrated just in one using the SELECT CASE Statement. I have worked with SELECT CASE statements in Word und Excel but for some reason I cannot get this one working with the codes above.

Regards, Andreas
0
 
LVL 23

Accepted Solution

by:
JSRWilson earned 1600 total points
ID: 38712202
Insert a normal shape with text  "Centre" and this code run from it

Sub trigger(oshp As Shape)
Static choice As Long
choice = choice + 1
If choice = 4 Then choice = 1
Select Case choice
Case Is = 1
oshp.TextFrame.TextRange = "180"
Call ResizeAndPosition_Pictures_ToggleButton_1
Case Is = 2
oshp.TextFrame.TextRange = "270"
Call ResizeAndPosition_Pictures_ToggleButton_2
Case Is = 3
oshp.TextFrame.TextRange = "Centre"
Call ResizeAndPosition_Pictures_ToggleButton_3
End Select
End Sub

(and your other code of course)
0
 

Author Closing Comment

by:AndreasHermle
ID: 38712299
Great support from professional experts.

Thank you very much. I really appreciate it.

Regards, Andreas
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question