这段代码之后
With Sheets("Sheet1")
ActiveSheet.Unprotect
Range("Q3:S5").Select
MyRange = Selection.Address
PicLocation = UserForm1.txtImage
If PicLocation <> "False" Then
ActiveSheet.Pictures.Insert(PicLocation).Select
Else
Exit Sub
End If
With Selection.ShapeRange
.LockAspectRatio = msoTrue
If .Width > .Height Then
.Width = Range(MyRange).Width
If .Height > Range(MyRange).Height Then .Height = Range(MyRange).Height
Else
.Height = Range(MyRange).Height
If .Width > Range(MyRange).Width Then .Width = Range(MyRange).Width
End If
End With
With Selection
.Placement = xlMoveAndSize
.PrintObject = True
End With
End With
`
我的图像不在我想要的合并单元格中(“ Q3:S5”)。
但是在Office 2010中,此代码就可以了。不幸的是,我需要在Office 2007中运行。
对不起,外部链接,但我没有上传图像的声誉。
另外,我希望图像处于“中间对齐”状态。
谢谢!
查看此版本的代码是否有效。将文件名更改为所需的名称。
Sub Button1_Click()
Set myRng = Range("Q3:S5")
Set mypict = myRng.Parent.Pictures.Insert("C:\Users\Dave\Downloads\9-29-2015 4-21-06 AM.jpg")
mypict.Top = myRng.Top
mypict.Width = myRng.Width
mypict.Height = myRng.Height
mypict.Left = myRng.Left
mypict.Placement = xlMoveAndSize
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句