Consulting

Results 1 to 8 of 8

Thread: Need assist with VBA in PPT

  1. #1

    Need assist with VBA in PPT

    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


    Capture.JPG

  2. #2
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,645
    Location
    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
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    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. :-)

  4. #4
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,645
    Location
    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
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,863
    Location
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    All slides havethe same basic 5 pieces, except the last one (which only has one picture and title).

    Sample I adjusted by hand: final.JPG
    Sample with the pictures at original size, no adjustments: orig.JPG

    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.

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,863
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •