Sub Ex()
Dim j As Integer, MyPath As String, MyFile As String, k, l
For k = 1 To 2
For l = 4 To 5
j = 2
While Cells(j, "C") <> "" 'C2為檔名
MyPath = Cells(j, k) 'A2 B2為位址
If UCase(Cells(j, "C")) Like "*W*" Then '字串中有"ABCD"
' UCase 函數 傳回一個 Variant (String),所含為轉成大寫之字串。
Cells(j, l).Select 'D2 E2為圖片
On Error Resume Next
MyFile = Dir(MyPath & "*" & Cells(j, "C") & "*.*") ' C2 = "ABCD" ->"1AABCD.png"
If MyFile <> "" Then
With ActiveSheet.Pictures.Insert(MyPath & MyFile)
' .ShapeRange.LockAspectRatio = msoTrue
' 在調整圖案大小時,可以分別地調整圖案的長度和寬度
.ShapeRange.LockAspectRatio = msoFalse
.ShapeRange.Height = 100#
.ShapeRange.Width = 100#
.ShapeRange.Rotation = 0#
.Placement = xlMoveAndSize
.PrintObject = True
End With
End If
End If
j = j + 1
Wend
Range("C2").Select
Next
Next
End Sub作者: c_c_lai 時間: 2012-12-15 11:19