Solved

toggle between different alignments of pictures by means of VBA

Posted on 2012-12-20
5
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 100 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 400 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 400 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 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