none
powerpoint fit image RRS feed

  • Question

  • Hi, I'm replacing a linked image in powerpoint via the .LinkFormat.SourceFullName property, which is working fine.

    After a file update, I only need to execute the functionality as you have in the UI via Picture tools format, crop, fit. To make the image resized within its proportions.

    I can't find an easy way to execute that same function in code. How can I execute that specific command from the commandbar directly, or via code.

    thanks.

    Wednesday, May 4, 2016 1:07 PM

Answers

  • >>>then I get an error on the .select saying: "Shape (unknown member) : Invalid request.  To select a shape, its view must be active."

    Maybe it is not possible execute this function when in slideshow mode. Is there maybe an alternative by code?<<<

    Based on my testing, it is possible execute this function when in slideshow mode, you could use ActionSetting Object to contain information about how the specified shape or text range reacts to mouse actions during a slide show, refer to below VBA code:
    Sub DemoChagePictute()
      
        With ActivePresentation.Slides(1).Shapes(1)
    
            Debug.Print .LinkFormat.SourceFullName
            
            .LinkFormat.SourceFullName = "picture file path"
            .LinkFormat.Update
            .Select
            
            Application.CommandBars.ExecuteMso ("PictureFitCrop")
        
        End With
        
    End Sub
    
    Sub DemoSetMacroAction()
    
        With ActivePresentation.Slides(1).Shapes(1).ActionSettings(ppMouseClick)  ' or ppMouseOver if you prefer
        
            .Run = "DemoChagePictute"
            .Action = ppActionRunMacro
             
        End With
    End Sub

    But "Application.CommandBars.ExecuteMso ("PictureFitCrop")" this line code don't make of affect, you are not able to change picture via Picture tools format, crop, fit.

    For more information, click here to refer about ActionSetting Object

    So I suggest that you could submit feedback about Powerpoint from link below:

    https://powerpoint.uservoice.com/

    Thanks for your understanding.
    • Marked as answer by David_JunFeng Thursday, May 12, 2016 5:06 AM
    Friday, May 6, 2016 2:13 AM

All replies

  • >>>I can't find an easy way to execute that same function in code. How can I execute that specific command from the commandbar directly, or via code.

    According to your description, you could use CommandBars.ExecuteMso method to execute the control identified by the idMso parameter.
    Application.CommandBars.ExecuteMso ("PictureFitCrop")
    For more information, click here to refer about CommandBars.ExecuteMso Method (Office)

    In addition information about each of the control IDs for built-in UI commands and menu items in all applications that use the Office 2013 Fluent UI:

    Office 2013 Help Files: Office Fluent User Interface Control Identifiers

    Thursday, May 5, 2016 3:21 AM
  • Thanks David, but I need to run this when the slideshow is running.

    When I use the code like this: (s is of type powerpoint.shape)

          S.LinkFormat.SourceFullName = fn
          S.LinkFormat.Update()
          S.Select()
          Globals.ThisAddIn.Application.CommandBars.ExecuteMso("PictureFitCrop")

    then I get an error on the .select saying: "Shape (unknown member) : Invalid request.  To select a shape, its view must be active."

    Maybe it is not possible execute this function when in slideshow mode. Is there maybe an alternative by code?

    Thursday, May 5, 2016 8:40 AM
  • >>>then I get an error on the .select saying: "Shape (unknown member) : Invalid request.  To select a shape, its view must be active."

    Maybe it is not possible execute this function when in slideshow mode. Is there maybe an alternative by code?<<<

    Based on my testing, it is possible execute this function when in slideshow mode, you could use ActionSetting Object to contain information about how the specified shape or text range reacts to mouse actions during a slide show, refer to below VBA code:
    Sub DemoChagePictute()
      
        With ActivePresentation.Slides(1).Shapes(1)
    
            Debug.Print .LinkFormat.SourceFullName
            
            .LinkFormat.SourceFullName = "picture file path"
            .LinkFormat.Update
            .Select
            
            Application.CommandBars.ExecuteMso ("PictureFitCrop")
        
        End With
        
    End Sub
    
    Sub DemoSetMacroAction()
    
        With ActivePresentation.Slides(1).Shapes(1).ActionSettings(ppMouseClick)  ' or ppMouseOver if you prefer
        
            .Run = "DemoChagePictute"
            .Action = ppActionRunMacro
             
        End With
    End Sub

    But "Application.CommandBars.ExecuteMso ("PictureFitCrop")" this line code don't make of affect, you are not able to change picture via Picture tools format, crop, fit.

    For more information, click here to refer about ActionSetting Object

    So I suggest that you could submit feedback about Powerpoint from link below:

    https://powerpoint.uservoice.com/

    Thanks for your understanding.
    • Marked as answer by David_JunFeng Thursday, May 12, 2016 5:06 AM
    Friday, May 6, 2016 2:13 AM