插入时为照片添加边框

我正在制作一个简化为我公司撰写报告的工具。 这份报告需要插入一些照片,resize和解释。 我在Excel中创build了一个表格来解释照片,并根据我们使用的类似报告编写了一些VBA代码。 为了保持Excel生成的报告和W​​ord生成的报告之间的格式,我需要添加一个边框的图片,并希望这样做,因为照片导入。

谁能帮我这个?

“If”声明的其余部分将调整照片大小。

Sub Pic() ' 'Pic Macro ' Dim PLog As String Dim Photo As String Dim a As Integer Dim b As Integer Dim c As Integer Dim d As Integer Dim Bottom As String Dim bot As Integer Dim PrintA As String Dim Top As String Application.ScreenUpdating = False Sheets("Photo Log").Select a = 5 b = 1 PLog = "PLog" & b Photo = "Input!Q" & a While a < 152 PLog = "PLog" & b Photo = "Input!Q" & a If Range(Photo) <> "" Then Range("PLog1").Select ActiveSheet.Pictures.Insert( _ Range("PhotoPath") & "\" & Range("SiteID") & " (" & Range(Photo) & ").jpg" _ ).Select 

首先在插入图像时使用Shape对象。 避免使用。select。 其次使用形状的.Line.Weight.Line.Visible来获得边框。

 ' '~~> Rest of the code ' Dim MyPic As Shape Set MyPic = ActiveSheet.Pictures.Insert(Range("PhotoPath") & "\" & _ Range("SiteID") & " (" & _ Range(Photo) & ").jpg" _ ) '~~> Insert Border With MyPic .Line.Weight = 8 .Line.Visible = msoTrue End With ' '~~> Rest of the code '