从提示输入中解锁纵横比
Unlock Aspect Ratio from Prompted Input
我在 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
当您尝试插入图片时,请将类型声明为 Picture
而不是 Object
。 ShapeRange
属性.
下可以使用LockAspectRatio
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
我在 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
当您尝试插入图片时,请将类型声明为 Picture
而不是 Object
。 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