swetha
swetha

Reputation: 39

"Compile Error : Argument not optional" Error when trying to retrieve Shape.ScaleHeight value in VBA

I want to access the properties of an image present (Eg:Height,Width,ScaleHeight,Scale Width) in a slide, in a PPT using VBA.

But,unable to retrieve the values of 'ScaleHeight','ScaleWidth' of images.It throws the following error: "Compile Error : Argument not optional"

How can we retrieve these two values for an image, as we can get Height using Shape.Height

Here is my Code

 Select Case Shp.Type
     
      Case msoPicture
            Debug.Print Shp.Id
            Debug.Print Shp.Height
            Debug.Print Shp.Width
            Debug.Print Shp.ScaleHeight
            Debug.Print Shp.ScaleWidth

 End Select                   
        
                    

Upvotes: 0

Views: 416

Answers (1)

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

ScaleHeight/ScaleWidth are not properties, they're methods that are used when resizing a shape. It's unclear what you hope to do; might be a good idea to make that clear.

This may help, from an older version of PPT/VBA help.

PowerPoint Developer Reference Shape.ScaleHeight Method Scales the height of the shape by a specified factor.

Syntax expression.ScaleHeight(Factor, RelativeToOriginalSize, fScale)

expression A variable that represents a Shape object.

Parameters

Name Required/Optional Data Type Description Factor Required Single Specifies the ratio between the height of the shape after you resize it and the current or original height. For example, to make a rectangle 50 percent larger, specify 1.5 for this argument. RelativeToOriginalSize Required MsoTriState Specifies whether the shape is scaled relative to its current or original size. fScale Optional MsoScaleFrom The part of the shape that retains its position when the shape is scaled.

Remarks

For pictures and OLE objects, you can indicate whether you want to scale the shape relative to its original size or relative to its current size. Shapes other than pictures and OLE objects are always scaled relative to their current height.

The RelativeToOriginalSize parameter value can be one of the following MsoTriState constants. You can specify msoTrue for this parameter only if the specified shape is a picture or an OLE object.

Constant Description msoFalse Scales the shape relative to its current size.
msoTrue Scales the shape relative to its original size.

The fScale parameter value can be one of the following MsoTriState constants. The default is msoScaleFromTopLeft.

msoScaleFromBottomRight msoScaleFromMiddle msoScaleFromTopLeft

Example This example scales all pictures and OLE objects on myDocument to 175 percent of their original height and width, and it scales all other shapes to 175 percent of their current height and width.

Set myDocument = ActivePresentation.Slides(1)
For Each s In myDocument.Shapes
    Select Case s.Type
    Case msoEmbeddedOLEObject, msoLinkedOLEObject, _
            msoOLEControlObject, msoLinkedPicture, msoPicture 
        s.ScaleHeight 1.75, msoTrue
        s.ScaleWidth 1.75, msoTrue
    Case Else
        s.ScaleHeight 1.75, msoFalse
        s.ScaleWidth 1.75, msoFalse
    End Select
Next 

Upvotes: 1

Related Questions