Image 在VBA将图像插入WS时向图像添加边框线
我有代码将图像插入WS中的特定单元格,如下所示: =============================================================Image 在VBA将图像插入WS时向图像添加边框线,image,vba,border,Image,Vba,Border,我有代码将图像插入WS中的特定单元格,如下所示: ============================================================= Sub LoadPict() Dim Pict As String Dim cl As Range Pict = "D:\Picture.JPG" Set Rng = Range("D2") For Each cl In Rng Set myPicture = ActiveSheet.Pictures.Inser
Sub LoadPict()
Dim Pict As String
Dim cl As Range
Pict = "D:\Picture.JPG"
Set Rng = Range("D2")
For Each cl In Rng
Set myPicture = ActiveSheet.Pictures.Insert(Pict)
With myPicture
.ShapeRange.LockAspectRatio = msoFalse
.Height = 150
.Width = 144.75
.Top = Rows(cl.Row).Top
.Left = Columns(cl.Column).Left
.PrintObject = True
End With
Next
End If
End Sub
=============================================================
Sub LoadPict()
Dim Pict As String
Dim cl As Range
Pict = "D:\Picture.JPG"
Set Rng = Range("D2")
For Each cl In Rng
Set myPicture = ActiveSheet.Pictures.Insert(Pict)
With myPicture
.ShapeRange.LockAspectRatio = msoFalse
.Height = 150
.Width = 144.75
.Top = Rows(cl.Row).Top
.Left = Columns(cl.Column).Left
.PrintObject = True
End With
Next
End If
End Sub
问题是,要添加哪些代码,以便我插入的图片周围自动有边框线
感谢您花时间帮助我。在Excel 2003或更高版本中,尝试使用Shapes.AddPicture方法添加图像,并使用Shape.Line属性设置边框
Sub LoadPict()
Dim Pict As String
Dim cl As Range
Dim myPicture As Shape
Pict = "D:\Picture.JPG"
Set Rng = Range("D2")
For Each cl In Rng
Set myPicture = ActiveSheet.Shapes.AddPicture(Pict, msoFalse, msoTrue, cl.Left, cl.Top, 144.75, 150)
With myPicture
.Line.Weight = 8
.Line.Visible = msoTrue
Next
End Sub