PDA

View Full Version : Need assist with VBA in PPT



TrainTrainer
09-05-2019, 09:56 PM
See attached slide for reference. Using Office 2016.

I have a slideshow of 250+ slides, I need VBA code to make formatting adjustments to conform all slides to each other. I am currently learning VBA but concentrating on Excel so the code for this is completely outside my scope of expertise. I have thus far toyed with some snippets of code I have found in my searches and I'm not having any luck with them.

Here are the requirements for each section of the slide:

Box A - Title Box - Description: Title, 1 line. No adjustments needed, they are identical across the presentation and need no changes
Box B - Text Box - Description: text box with two lines of text.
Adjustments needed

text Calibri 27 pt
box 1” height, 5.65” width, Horizontal position 0.92“ from top left, vertical position 1.84” from top left

Box C - Text Box - Description: text box with two lines of text.
Adjustments needed:

text Calibri 27 pt
box 1” height, 5.65” width, Horizontal position 6.80“ from top left, vertical position 1.84” from top left

Box D - Image (images vary in size across all slides)
Adjustments needed:

Size: Image Height 4.50", Lock aspect ratio
Position: Horizontal position 2.30“ from top left, vertical position 2.83” from top left

Box E - Image (images vary in size across all slides)
Adjustments needed:

Size: Image Height 4.50", Lock aspect ratio
Position: Horizontal position 7.86“ from top left, vertical position 2.83” from top left


24942

Paul_Hossler
09-06-2019, 07:46 AM
What I'd do

1. Fix my master slide(s) the way I wanted

2. Select all slides (I use Slide Sorter view)

3. Reset -- Home, Slides, Reset

4. Tweak as necessary

That assumes that things are in placeholders, and not a lot of ad hoc text boxes

TrainTrainer
09-06-2019, 01:30 PM
Thanks for the suggestion. That actually reset my font colors and changed all of my pictures back to their original sizes. The presentation has 219 slides, so adjusting every picture ( 2 x slide) to the exact same size by hand is extremely time consuming and honestly makes my hand hurt. Hoping someone will be able to assist with the code. :-)

Paul_Hossler
09-09-2019, 05:54 AM
Do all slides have the same 5 basic 'pieces' and you just want to have everything positioned and sized consistently?

I've always found the trickiest part is making sure the macro identifies each shape, etc. correctly, so if B, C, D, and E are approximately correct, you could probably make assumption based on position of Top Left


Attach a small sample presentation

John Wilson
09-09-2019, 11:01 AM
Hard to be sure without a sample but it seems to me if the images are different shapes and you set to the same height ... either they will distort or the width will change and maybe overlap.

TrainTrainer
09-09-2019, 02:25 PM
All slides havethe same basic 5 pieces, except the last one (which only has one picture and title).

Sample I adjusted by hand: 24982
Sample with the pictures at original size, no adjustments: 24983

Leaving the aspect ratio will prevent the image being blurred or misshapen. The slides have plenty of room to adjust the sizes with no overlap.

John Wilson
09-10-2019, 05:34 AM
Maybe this would do it but I doubt the left positions you ask for are what you need!


Sub fixPH()

Dim oshp1 As Shape
Dim oshp2 As Shape
Dim osld As Slide
Dim L As Long
Dim b_continue As Boolean
For Each osld In ActivePresentation.Slides
For L = 1 To osld.Shapes.Count
If osld.Shapes(L).Type = msoPlaceholder Then
If osld.Shapes(L).PlaceholderFormat.ContainedType = msoPicture Then
If Not b_continue Then
Set oshp1 = osld.Shapes(L)
b_continue = True
Else
Set oshp2 = osld.Shapes(L)
End If
End If
End If
Next L
If oshp1.Left < oshp2.Left Then
oshp1.LockAspectRatio = True
oshp1.Height = 4.5 * 72
oshp1.Left = 2.3 * 72
oshp1.Top = 2.83 * 72
oshp2.LockAspectRatio = True
oshp2.Height = 4.5 * 72
oshp2.Left = 7.86 * 72
oshp2.Top = 2.83 * 72
Else
oshp2.LockAspectRatio = True
oshp2.Height = 4.5 * 72
oshp2.Left = 2.3 * 72
oshp2.Top = 2.83 * 72
oshp1.LockAspectRatio = True
oshp1.Height = 4.5 * 72
oshp1.Left = 7.86 * 72
oshp1.Top = 2.83 * 72
End If
b_continue = False
Next osld
End Sub

TrainTrainer
09-10-2019, 09:39 AM
That worked perfectly for the photos! Thank you! The Title boxes (b & c) are still a little wonky on some slides (a previous code I tried to put together messed them up), but that is still A LOT less work for me. Thanks again!