1)请在Excel应用程序中运行以下代码。
Sub Macro1()
'Delete all shapes if exists
For i = ActiveSheet.Shapes.Count To 1 Step -1
ActiveSheet.Shapes(i).Delete
Next i
'Add a Rectangle
With ActiveSheet.Shapes.AddShape(Type:=msoShapeRectangle, Left:=20, Top:=20, Width:=200, Height:=120)
.Name = "myRectangle"
End With
'Make some formatting to the myRectangle
With ActiveSheet.Shapes("myRectangle")
.Line.Visible = msoTrue
.Line.ForeColor.RGB = vbBlue
.Line.Weight = 5
.Fill.UserPicture "https://upload.wikimedia.org/wikipedia/en/b/ba/Flag_of_Germany.svg"
End With
End Sub
2)请检查您的Excel 工作表中是否有以下矩形。
3)我正在寻找一个可以给我以下图片的宏。
正如您所理解的,我想在边界和旗帜之间留出一些空白。
请尝试
.PictureFormat.Crop
获取您的预期输出。Microsoft 文档:
有很多方法可以尝试,也许最简单的方法是在第一个矩形的中间添加另一个较小的矩形: