Solved

toggle between different alignments of pictures by means of VBA

Posted on 2012-12-20
5
398 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 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Paint/Redraw window while dragging 16 88
vb6 connector to mongodb 2 141
VB6 ListBox Question 4 56
Win 10 Automation Error with .doCmd in Access 2 29
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

733 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