Solved

toggle between different alignments of pictures by means of VBA

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now