从提示输入中解锁纵横比

时间:2017-11-15 16:47:10

标签: vba excel-vba aspect-ratio excel

我在$day=11/21/2017 $today=Get-Date if (Today=$day) { echo"Happy 18th Birthday [Jular]"} else { echo"Eat Cake Anyway" } 收到编译错误。我试图做的就是解锁从用户导入的图像的宽高比。我会假设我没有使用正确的语法,任何帮助都会很棒

img.LockAspectRatio = msoFalse

1 个答案:

答案 0 :(得分:1)

当您尝试插入图片时,请将类型声明为Picture而不是Object。使用LockAspectRatio在ShapeRange属性下可用。

Sub ChangeImage()
        With Application.FileDialog(msoFileDialogFilePicker)
            .AllowMultiSelect = False
            .ButtonName = "Submit"
            .Title = "Select an image file"
            .Filters.Clear
            .Filters.Add "All Pictures", "*.*"

            If .Show = -1 Then
                Dim img As Picture '/ Declare as Picture
                Set img = ActiveSheet.Pictures.Insert(.SelectedItems(1))


               '/ Use ShapeRange to toogle aspect ratio
               img.ShapeRange.LockAspectRatio = msoFalse


                img.Left = 141
                img.Top = 925

                img.Width = 600
                img.Height = 251
            Else
                Debug.Print "Prompt closed"
            End If
        End With
    End Sub