VBA Excel border around the picture

ぐ巨炮叔叔 提交于 2021-02-11 16:52:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!