Results 1 to 3 of 3

Thread: Making Compress Pictures Dialogue Box Selections in Mac

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Nov 2023
    Posts
    1
    Location

    Lightbulb

    Finally, I made it work using a combination of both AppleScripts and VBA Macros.

    So, basically, I started the macro execution from AppleScript and the macros does its thing until it reaches the Compress Images dialog.
    The macro is saved on a centrally macro-enabled file that I left open all the time while needing this.

    Later, I hit ENTER / RETURN using AppleScript so that the macro can continue.

    This is the AppleScript:

    on compactImages(ppt)
        tell application "Microsoft PowerPoint"
            open ppt
            activate
            repeat until frontmost
                delay 0.1
            end repeat
        end tell
        
        tell application "System Events"
            click menu item "Macros..." of menu "Macro" of menu item "Macro" of menu "Tools" of menu bar item "Tools" of menu bar 1 of application process "PowerPoint"
            delay 0.1
            -- choose workbook with Macros
            tell pop up button 1 of window 1 of application process "PowerPoint"
                click
                click menu item 2 of menu 1
            end tell
            delay 0.03
            -- choose the right macro
            tell text field 1 of window 1 of application process "PowerPoint"
                set value to "OpenDialogCompressPicturesAndSaveAndClose"
            end tell
            delay 0.5
            -- run it
            click button "Run" of window 1 of application process "PowerPoint"
            
    		
    
    
            -- Compress Pictures dialog
            delay 0.5
            -- choose> "On-screen (150 ppi)"
            tell pop up button 1 of group 1 of window 1 of application process "PowerPoint"
                click
                click menu item 4 of menu 1
            end tell
            -- choose "All pictures in this file"
            click radio button 1 of radio group 1 of group 1 of window 1 of application process "PowerPoint"
            delay 0.03
            -- click OK to compress all images
            keystroke return
        end tell
    end compactImages
    
    
    
    
    set ppts to (do shell script "ls '/<<YOUR-PATH>>/'*.pptx")'s paragraphs
    
    
    if ppts is {} then return
    
    
    repeat with ppt in ppts
        compactImages(ppt)
        log ppt
    end repeat

    This is the VBA macro:

    Sub OpenDialogCompressPicturesAndSaveAndClose()
        Dim shp As Shape
        Dim sld As Slide
        Dim atLeastOneImageSelected As Boolean
        Dim ppt As Presentation
        
        atLeastOneImageSelected = False
        For Each sld In ActivePresentation.Slides
            sld.Select
            For Each shp In sld.Shapes
                If shp.Type = msoPicture Then
                    shp.Select
                    atLeastOneImageSelected = True
                    Exit For
                ElseIf shp.Type = msoPlaceholder Then
                    If shp.PlaceholderFormat.ContainedType = msoPicture Then
                        shp.Select
                        atLeastOneImageSelected = True
                        Exit For
                    End If
                End If
            Next shp
            
            If atLeastOneImageSelected Then Exit For
        Next sld
    
    
        If atLeastOneImageSelected Then
            CommandBars.ExecuteMso "PicturesCompress"
        End If
    
    
        'Now I want to save the presentation and close it without closing other open PowerPoint files
        With Application.ActivePresentation
            If Not .Saved And .Path <> "" Then .Save
        End With
    
    
        'If PowerPoint.Application.Version >= 9 Then
        '    PowerPoint.Application.Visible = msoTrue
        'End If
        PowerPoint.ActivePresentation.Close
    End Sub
    Last edited by paespi; 11-13-2023 at 07:42 AM. Reason: Fix

Tags for this Thread

Posting Permissions

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