Consulting

Results 1 to 11 of 11

Thread: Solved: Macro / VBA to Compress Picture

  1. #1

    Solved: Macro / VBA to Compress Picture

    I am delivering a polwerpoint presentation to a large sales force. I am offering all automation via objects (buttons, text fields, etc) which are visible when in View Show Mode. I need to deliver the same functionality for compressing pictures which can be achieved by doing the following:

    Format Pictures -->
    Compress -->
    Apply to All Pictures in document

    I have tried using macro record to see how powerpoint would reflect the steps and the resulting macros is blank.

    The best idea I have read so far is to utilize "send keys" but this has serious challenges as well....

    I have done some research and this is evidently a tough issue. Major gold star for anyone who can help me find a good solution. Btw, the end game is too optimize file size reduction.

    Thanks

  2. #2
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Well, the quick answer is to check out PPTools. They have an addin specifically for this (called "Optimizer") and it works great:
    http://www.pptools.com/downloads.htm
    Office 2010, Windows 7
    goal: to learn the most efficient way

  3. #3
    Quote Originally Posted by TrippyTom
    Well, the quick answer is to check out PPTools. They have an addin specifically for this (called "Optimizer") and it works great:
    http://www.pptools.com/downloads.htm
    Thank you for the suggestion. My main concern with that solution is that I need to be able to distribute the presentaiton and all addins need to be installed on the client.

    Do you know if there is a way to distribute a presentation with the pptools addin intact? I would purchase it in a second!

  4. #4
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    I'm not sure. I have emailed the author of those tools and he's a really nice guy. I'm only assuming, but he might be able to work out a deal if he doesn't have one in place already.

    I would still like to know how to do this myself - just for learning sake.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  5. #5
    Quote Originally Posted by TrippyTom
    I'm not sure. I have emailed the author of those tools and he's a really nice guy. I'm only assuming, but he might be able to work out a deal if he doesn't have one in place already.

    I would still like to know how to do this myself - just for learning sake.
    You are a good man! Thank you for making the inquiry on my behalf. I will stay tuned. Meanwhile, if I figure something out I'll post the solution.

    Thanks again

  6. #6
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Nonono... I meant I emailed him in the past for other addins he wrote!

    The shape styles and starter set he wrote are very useful! I paid him for both of those because I use it so much.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  7. #7
    OK. No Problem. I'll email the author myself and see if he can offer any advise. Even with a fee it would be worth it.
    You're still a good man Trippy!

  8. #8
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Here's another one that seems to be cheaper, but I haven't tried it. Maybe it doesn't work as well.

    http://www.nxpowerlite.com/index.php?ld=n
    Office 2010, Windows 7
    goal: to learn the most efficient way

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Q: would you not want to compress all the pictures before distributing the presentation?

    It sounds to me like you want the end users to be able to compress the picture, similar to a navigation Action Button, and I can't see how they would need to do that?

    If you just want to make the file size small, PP2003+ has a Compress Picture option. From Help:

    1. Select one or more pictures (picture: A file (such as a metafile) that you can ungroup and manipulate as two or more objects or a file that stays as a single object (such as bitmaps).) in a file.
    2. On the Picture toolbar (toolbar: A bar with buttons and options that you use to carry out commands. To display a toolbar, click Customize on the Tools menu, and then click the Toolbars tab.), click Compress Picture http://office.microsoft.com/global/i...ZA060437461033. Note If you do not see the Picture toolbar, point to View, then point to Toolbars, and then click Picture.
    3. Select the options you want.
    Note Selecting the Delete cropped areas of pictures check box discards the parts of the picture that were hidden during cropping (crop: To trim vertical or horizontal edges of an object. Pictures are often cropped to focus attention on a particular area.).

    Paul

  10. #10
    Quote Originally Posted by dumbpuppy
    I am delivering a polwerpoint presentation to a large sales force. I am offering all automation via objects (buttons, text fields, etc) which are visible when in View Show Mode. I need to deliver the same functionality for compressing pictures which can be achieved by doing the following:

    Format Pictures -->
    Compress -->
    Apply to All Pictures in document

    I have tried using macro record to see how powerpoint would reflect the steps and the resulting macros is blank.

    The best idea I have read so far is to utilize "send keys" but this has serious challenges as well....

    I have done some research and this is evidently a tough issue. Major gold star for anyone who can help me find a good solution. Btw, the end game is too optimize file size reduction.

    Thanks
    Hi,

    I think sendkeys is the best solution together with FindControl. The following code works in PPT 2003 english version. You may need to change %A (Alt+a)and %W (Alt+W) to other keys to navigate the dialogbox.

    Sub compress()
    Application.CommandBars.FindControl(Id:=6382).Execute
    SendKeys "%A%W{ENTER}", False
    End Sub

    Happy programming


    /silvastre

  11. #11

    Thumbs up Thank you Silvastre ... Much cleaner solution

    Quote Originally Posted by silvastre
    Hi,

    I think sendkeys is the best solution together with FindControl. The following code works in PPT 2003 english version. You may need to change %A (Alt+a)and %W (Alt+W) to other keys to navigate the dialogbox.

    Sub compress()
    Application.CommandBars.FindControl(Id:=6382).Execute
    SendKeys "%A%W{ENTER}", False
    End Sub

    Happy programming


    /silvastre
    Fantastic!

    I am grateful you took the time to post your suggestion. I replaced the send key logic I had implemented which was not nearly as clean. See Below snippet. Keep in mind I was artificially selecting an image tagged as "picture"\"fake" to gain access to the menu items needed.

    [VBA]

    Sub AACompressImages()
    Dim oSh As Shape
    Dim lCurrSlide As Long
    Dim SlideName
    Dim intCurrSlide
    Dim oSlide As Slide
    On Error GoTo errhandler

    Set oSlide = ActivePresentation.Slides("chartmanage")
    lCurrSlide = oSlide.SlideIndex
    ActiveWindow.View.GotoSlide lCurrSlide
    Set oSh = Module3.GetShapeTaggedWith("picture", "fake", oSlide)
    If Not oSh Is Nothing Then ' we found it
    ActivePresentation.Application.DisplayAlerts = ppAlertsNone
    oSh.Select
    SendKeys "%oi", False
    SendKeys "%m", False
    SendKeys "aw{ENTER}{ESC}{ESC}", True
    Else
    MsgBox "Image Not found"
    End If

    Exit Sub
    errhandler:
    MsgBox "Error: " & Err.Number & " " & Err.Description

    End Sub
    [/VBA]

    Your code works flawlessly and also eliminates some other hoops I was jumping through. The compress images challenge has been a relative "hack" compared to other functionality I am delivering. This will serve to significantly clean up that process.

    Thank you very much!

    If I can humbly offer up any assistance with some issues I have worked through please feel free to post.

Posting Permissions

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