+ Reply to Thread
Results 1 to 8 of 8

Macro to reduce image sizes in a ppt that worked in ppt 2007 but not in ppt 2013

Hybrid View

  1. #1
    Registered User
    Join Date
    03-01-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2010
    Posts
    60

    Macro to reduce image sizes in a ppt that worked in ppt 2007 but not in ppt 2013

    Hi,

    I've a macro that I used with some ppt's in office 2007 to reduce the size of some links within the ppt to an excel file. Recently I've installed the Office 2013 and the macro crashed with the following error:

        Shape.select: invalid request. To select a shape, its view must be active
    Here is the code I have:

    Sub reduce()
     For Each curr_slide In ActivePresentation.Slides
         curr_slide.Select
           For Each oSh In curr_slide.Shapes
               If oSh.Type = msoLinkedOLEObject Then
                Set oSh = curr_slide.Shapes(3)
    
                 With oSh
                       '.LinkFormat.BreakLink
    
                       .Select
                       .LockAspectRatio = False
                       .Height = 14 * 28.33
                       .Width = 33.5 * 28.33
                       .Cut
                       Set oSh = curr_slide.Shapes.PasteSpecial(DataType:=ppPastePNG)
                       .Height = 10 * 28.33
                       .Width = 23 * 28.33
                       .Left = 1.2 * 28.33
                       .Top = 1.85 * 28.33
                       .ZOrder (msoSendToBack)
                   End With
               End If
           Next oSh
       Next curr_slide
    End Sub
    I believe now, I've to activate each shape in every slide but I don't know how to do it. I've tried to use an integer to point to each slide but I had no success.
    Can someone help me?!

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to reduce image sizes in a ppt that worked in ppt 2007 but not in ppt 2013

    Maybe you don't need the select, try just commenting it out.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    03-01-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2010
    Posts
    60

    Re: Macro to reduce image sizes in a ppt that worked in ppt 2007 but not in ppt 2013

    Quote Originally Posted by xladept View Post
    Maybe you don't need the select, try just commenting it out.
    Doing that, the error went to the paste data type. It gave me this:

    Shapes.PasteSpecial: Invalid request. The specified data type is unavailable.
    ???

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to reduce image sizes in a ppt that worked in ppt 2007 but not in ppt 2013

    Hi Adam,

    I have no idea - I'll present this thread to the community at large

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,971

    Re: Macro to reduce image sizes in a ppt that worked in ppt 2007 but not in ppt 2013

    • You do not need to select the slide
    • You are using oSh as a For..Next control variable; but then, inside the loop you are pointing it to two other shapes. You need to use a separate variable for that:
      Set oSh = curr_slide.Shapes(3) ... ---->....Set curr_shp = curr_slide.Shapes(3), etc.
    • I don't think you can use .PasteSpecial with the .Cut. Instead, maybe Copy, PasteSpecial, Cut curr_shp.Shapes(3) .... [What happens if there is no third shape?]

    I'm not sure about using SET with PasteSpecial
    Last edited by protonLeah; 09-26-2015 at 02:31 AM.
    Ben Van Johnson

  6. #6
    Registered User
    Join Date
    03-01-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2010
    Posts
    60

    Re: Macro to reduce image sizes in a ppt that worked in ppt 2007 but not in ppt 2013

    Quote Originally Posted by protonLeah View Post
    • You do not need to select the slide
    • You are using oSh as a For..Next control variable; but then, inside the loop you are pointing it to two other shapes. You need to use a separate variable for that:
      Set oSh = curr_slide.Shapes(3) ... ---->....Set curr_shp = curr_slide.Shapes(3), etc.
    • I don't think you can use .PasteSpecial with the .Cut. Instead, maybe Copy, PasteSpecial, Cut curr_shp.Shapes(3) .... [What happens if there is no third shape?]

    I'm not sure about using SET with PasteSpecial
    I commented out the select and it gave me the error related with the data type. I tried to use a separate variable for the shapes inside the loop but it also still gives me the data type error. Cut or copy also give the same result. There was no problem with the datatype in Office 2007 =\

    tks for the help!

    Sub reduce()
     For Each curr_slide In ActivePresentation.Slides
           For Each oSh In curr_slide.Shapes
               If oSh.Type = msoLinkedOLEObject Then
                 With curr_slide.Shapes(3)
                       '.LinkFormat.BreakLink
                       .Select
                       .LockAspectRatio = False
                       .Height = 14 * 28.33
                       .Width = 33.5 * 28.33
                       .Cut
                       Dim PastedShape as Shape
                       Set oPastedShape = curr_slide.Shapes.PasteSpecial(DataType:=ppPastePNG)
                      
                       With oPastedShape
                       .Height = 10 * 28.33
                       .Width = 23 * 28.33
                       .Left = 1.2 * 28.33
                       .Top = 1.85 * 28.33
                       .ZOrder (msoSendToBack)
                       End with
    
                   End With
               End If
           Next oSh
       Next curr_slide
    End Sub

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro to reduce image sizes in a ppt that worked in ppt 2007 but not in ppt 2013

    Sub M_snb()
     For Each sl In ActivePresentation.Slides
       For Each Sh In sl.Shapes
           If Sh.Type = msoLinkedOLEObject Then
              sh.Height = 283.3
              sh.Width = 33.5 * 28.33
              sh.Left = 1.2 * 28.33
              sh.Top = 1.85 * 28.33
           end if
        Next
     Next
    End Sub



  8. #8
    Registered User
    Join Date
    03-01-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2010
    Posts
    60

    Re: Macro to reduce image sizes in a ppt that worked in ppt 2007 but not in ppt 2013

    Hi

    I've solved the problem, basically by defining my datatype with the associated ID number instead of indicating the traditional "ppPasteXPTO". I've also used the number of the Bitmap format file instead of the PNG since it allows me to reduce the size of the ppt but it's not so heavy in the image compression like the PNG is. Here is the final code:

    Sub reduce()
    
    Dim shp As Shape
    Dim sld As Slide
    
    'Loop Through Each Slide in ActivePresentation
    For Each sld In ActivePresentation.Slides
        For Each shp In sld.Shapes
         If shp.Type = msoLinkedOLEObject Then
            shp.Cut
            Dim oShp As ShapeRange
            Set oShp = sld.Shapes.PasteSpecial(DataType:=1)
         End If
        Next shp
      Next sld
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA formatting macro that worked in Excel 2010 is not working correctly in Excel 2013
    By jayar2112 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2015, 01:14 PM
  2. Replies: 1
    Last Post: 06-08-2015, 03:15 PM
  3. Replies: 0
    Last Post: 06-08-2015, 03:07 PM
  4. [SOLVED] VB Macro to Auto Insert Two Checkboxes For Each Image in Excel 2007 Workbook
    By jcook1100 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 10-21-2014, 10:22 AM
  5. Replies: 7
    Last Post: 09-12-2013, 03:01 AM
  6. Charting Macro worked in 2003 but not in 2007
    By paulabrozek in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-01-2009, 02:28 PM
  7. Reduce image size before inserting.
    By Jay59 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-03-2007, 04:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1