- 帖子
- 29
- 主題
- 7
- 精華
- 0
- 積分
- 42
- 點名
- 0
- 作業系統
- XP
- 軟體版本
- OFFICE 2003
- 閱讀權限
- 10
- 註冊時間
- 2012-9-22
- 最後登錄
- 2013-1-9
|
回復 9# c_c_lai
幫我看一下
我想要在A欄B欄放位址
C欄為圖片檔名
D欄為顯示A的圖片
E欄顯示B的圖片
使用FOR 迴圈
圖片會在D欄重疊
該怎麼改呢
Option Explicit
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 |
|