问题
Good morning,
Precision my question from yesterday: VBA Excel border around the specified picture
I would like to make automatic borders for most of the images in my Excel document. I started to record the macro, which looks like this:
Sub Picbodred()
'
' Picbodred Macro
'
'
ActiveSheet.Shapes.Range(Array("Picture 2")).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
End With
End Sub
But it covers 1 image only, and as it worst this image has assigned ID, which won't be the same. On top of that I would like to keep some images without borders, as per the pattern below:
How can I do it?
回答1:
Actually, lemme just write this as an answer, hihi.
How about you name all pictures you want borders for like so: SomeName_Border and then run this macro:
Sub test()
For i = 1 To ThisWorkbook.Sheets("sheetname").Shapes.Count
If ThisWorkbook.Sheets("sheetname").Shapes(i).Name Like "*Border" Then
With ThisWorkbook.Sheets("Sheetname").Shapes(i).Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
End With
End If
Next
End Sub
just change the .somethingsomething from the macro recorder to anything recorded with it. If you maybe want thicker lines or something later I mean.
来源:https://stackoverflow.com/questions/60111267/vba-excel-border-around-the-picture