excel - 如何将边框应用于使用 VBA 在 Excel 工作表中作为图片元素(Dim var as Picture)插入的图像?
问题描述
我想使用变量将边框应用于插入到 excel 工作表中的图像:Dim Pic as Picture
来自本地目录(在此处下载后。)
我曾尝试在线搜索许多网站以寻求帮助,但没有任何帮助,因为其中大多数是针对 Shape 变量而不是针对 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
.
推荐阅读
- java - Java 双重数学
- c# - 如何按某些字段分组并用 epplus 对其他字段求和
- php - 如何通过嵌套的 Laravel 关系以雄辩的 ORM 方式进行查询
- elasticsearch - ElasticSearch:聚合一组结果
- python - 深度 Q 学习、LSTM 和 Q 值收敛
- javascript - Regex won't consider an optional group even if it's there
- javascript - vuejs v-model let it change from one place only
- java - 为什么添加套接字读取超时对 socketread0 没有帮助
- macros - Modification of a SAS macro to print dichotomous variable information
- python-2.7 - Python:如何将“请求”对象与会话范围的夹具一起使用