Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Image 在VBA将图像插入WS时向图像添加边框线_Image_Vba_Border - Fatal编程技术网

Image 在VBA将图像插入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

我有代码将图像插入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.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