none
Excel VBA does not change graph width RRS feed

  • Question

  • Hi,

    I have the following VBA code to add a graph to a PowerPoint slide.

    WSFleetPerfTwo.ChartObjects("Chart 3").Copy
        newPowerPoint.ActivePresentation.Slides(5).Select
        newPowerPoint.ActivePresentation.Slides(5).Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
    
        Set ShapePP = newPowerPoint.ActivePresentation.Slides(5).Shapes(newPowerPoint.ActivePresentation.Slides(5).Shapes.Count)
    
        With ShapePP
    
            .Top = 200
            .Left = 50
            .Width = 300
            .Height = 200
    
        End With

    Now this is the problem: the code takes over the graph and paste it the same size as in the Excel file. I want that Excel resizes the graph for PowerPoint, but it does not do that somehow.

    Note: the Top and Left do work.

    Can anyone help?

    Thanks.


    Friday, December 9, 2016 12:58 PM

Answers

  • Hi,

    Add line

    ShapePP.LockAspectRatio = msoFalse

    before 

    With ShapePP
    Regards,
    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ganeshgebhard Monday, December 12, 2016 10:23 AM
    Monday, December 12, 2016 10:09 AM
    Moderator

All replies

  • Hi,

    I have the following VBA code to add a graph to a PowerPoint slide.

    WSFleetPerfTwo.ChartObjects("Chart 3").Copy
        newPowerPoint.ActivePresentation.Slides(5).Select
        newPowerPoint.ActivePresentation.Slides(5).Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
    
        Set ShapePP = newPowerPoint.ActivePresentation.Slides(5).Shapes(newPowerPoint.ActivePresentation.Slides(5).Shapes.Count)
    
        With ShapePP
    
            .Top = 200
            .Left = 50
            .Width = 300
            .Height = 200
    
        End With

    Now this is the problem: the code takes over the graph and paste it the same size as in the Excel file. I want that Excel resizes the graph for PowerPoint, but it does not do that somehow.

    Note: the Top and Left do work.

    Can anyone help?

    Thanks.


    Wednesday, December 7, 2016 1:09 PM
  • Hi,

    Thanks for posting in SharePoint 2013 Development and Programming forum.

    This forum is for developers discussing developing issues involve SharePoint 2013 product like customization and automation. Since the issue is more relative to office, I would move it to Microsoft Office for Developers: General Office Development forum.

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. 

    Thanks for your understanding.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, December 8, 2016 3:08 AM
  • Hi,

    I do not see any reason why it should not work.

    Probably if you can share your excel workbook of course with dummy data (in case of secured data). It would e helpful to find the issue.


    Vish Mishra

    Friday, December 9, 2016 2:17 PM
  • Thanks for the response.

    The sheet indeed consist confidential data. Problem is that I can not build a dummy file, because that would take me a whole day to achieve.

    I'm sorry. 

    Friday, December 9, 2016 2:30 PM
  • Hi,

    The reason why I ask is, I can not see the error in your part of code you posted here. I tried it in Excel sheet in my system and it works perfectly and able to resize the graph in PPT.

    Regards,


    Vish Mishra

    Friday, December 9, 2016 3:22 PM
  • Then...I have no idea what's wrong here.
    Monday, December 12, 2016 8:35 AM
  • Hi,

    We need to set Shape.LockAspectRatio Property (PowerPoint) into msoFalse for the shape, then we could resize it into custom size.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 12, 2016 10:03 AM
    Moderator
  • Hi Celeste,

    How would that look like in my code?

    Thanks

    Monday, December 12, 2016 10:04 AM
  • Hi,

    Add line

    ShapePP.LockAspectRatio = msoFalse

    before 

    With ShapePP
    Regards,
    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ganeshgebhard Monday, December 12, 2016 10:23 AM
    Monday, December 12, 2016 10:09 AM
    Moderator
  • Hi,

    Thanks for the response, but it doesn't work..

    UPDATE

    It works, but without 'mso'. Just 'False'.


    Monday, December 12, 2016 10:20 AM