如何使用VBA将边框应用于Excel工作表中作为图片元素插入的图像(暗淡的变量为图片)?



我想使用变量将边框应用于插入 excel 工作表中的图像:从本地目录Dim Pic as Picture(下载到那里后。

我试图在线搜索许多网站寻求帮助,但到目前为止没有帮助,因为它们中的大多数都是针对形状变量而不是图片变量的。

我是否也必须使用形状变量,或者有没有办法在我键入"Pic"时应用边框,然后我可以看到可用的 Pic.border 选项,但我不知道如何使用它。请对此提供帮助。

.....
URLDownloadToFile 0, imgsrc, dlpath & code + ".jpg", 0, 0
Dim PicPath As String, Pic As Picture, ImageCell As Range
PicPath = dlpath & unique_code & ".jpg"
Set ImageCell = Cells(i, "C").MergeArea
Set Pic = ActiveSheet.Pictures.Insert(PicPath)
Rows(i).RowHeight = 160
With Pic
.ShapeRange.LockAspectRatio = msoTrue
.Left = ImageCell.Left
.Top = ImageCell.Top
.Width = ImageCell.Width
.Height = ImageCell.Height
End With
.....

需要对这些图像应用边框。

我想用细边框包围图片。截至目前,它们正在覆盖它们所属细胞的边界

要添加边框,例如宽度 1,请按如下方式修改With代码部分:

With Pic
.ShapeRange.LockAspectRatio = msoTrue
With .ShapeRange.Line
.Visible = msoTrue
.Weight = 1
End With
.Left = ImageCell.Left
.Top = ImageCell.Top
.Width = ImageCell.Width
.Height = ImageCell.Height
End With

您可以在嵌套With中添加任何其他边框参数。

最新更新