Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 从提示输入解锁纵横比_Vba_Excel_Aspect Ratio - Fatal编程技术网

Vba 从提示输入解锁纵横比

Vba 从提示输入解锁纵横比,vba,excel,aspect-ratio,Vba,Excel,Aspect Ratio,我在img.LockAspectRatio=msoFalse上得到一个编译错误。我所要做的就是解锁从用户导入的图像的纵横比。我假设我没有使用正确的语法,任何帮助都会很好 Sub ChangeImage() With Application.FileDialog(msoFileDialogFilePicker) .AllowMultiSelect = False .ButtonName = "Submit" .Title = "Select

我在img.LockAspectRatio=msoFalse上得到一个编译错误。我所要做的就是解锁从用户导入的图像的纵横比。我假设我没有使用正确的语法,任何帮助都会很好

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 Object
            Set img = ActiveSheet.Pictures.Insert(.SelectedItems(1))

            img.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

在尝试插入图片时,请将类型声明为图片而不是对象。Use LockAspectRatio在ShaperAge属性下可用

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

@braX感谢您的建议,但这并没有真正帮助我的问题,因为我宣布它为对象,而它本应该是一张图片,因为cyboashu已经正确地回答了我的问题