插入

时间:2015-11-07 04:12:19

标签: excel vba excel-vba

我正在研究一种简化为公司撰写报告的工具。此报告需要插入,调整大小和解释许多照片。我在Excel中创建了一个表来解释照片,并根据我们使用的类似报告编写了一些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

1 个答案:

答案 0 :(得分:1)

首先在插入图像时使用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
'