2015-11-07 18 views
1

我正在使用一種工具簡化爲我公司編寫報告的工作。這份報告需要插入一些照片,調整大小和解釋。我在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

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