- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
|
5#
發表於 2014-6-1 07:01
| 只看該作者
本帖最後由 GBKEE 於 2014-6-1 20:28 編輯
回復 4# jaga0828
試試看- Option Explicit
- Sub Ex()
- Dim AR(), i As Integer, ii As Integer, fs As String, Rng As Range
- With ActiveSheet
- .Cells = ""
- .Pictures.Delete
- fs = Dir("D:\test\*.jpg")
- Do Until fs = ""
- ReDim Preserve AR(0 To i)
- AR(i) = fs '圖片名稱置入陣列
- fs = Dir
- i = i + 1
- Loop
- For i = 0 To UBound(AR) Step 2
- For ii = 0 To 1
- If ii + i <= UBound(AR) Then
- .Cells(Int(i / 2) + 1, 1 + (ii * 2)) = AR(ii + i)
- Set Rng = .Cells(Int(i / 2) + 1, 2 + (ii * 2))
- With .Pictures.Insert("D:\test\" & AR(ii + i))
- .Top = Rng.Top
- .Left = Rng.Left
- .Width = Rng.Width
- .Height = Rng.Height
- End With
- End If
- Next
- Next
- End With
- End Sub
複製代碼- Sub Ex_1()
- Dim f As Object, E As Object, Rng As Range, i As Integer
- Set f = CreateObject("Scripting.FileSystemObject").getfolder("D:\test").Files
- With ActiveSheet
- .Cells = ""
- .Pictures.Delete
- i = 1
- For Each E In f
- If LCase(E) Like "*.jpg" Then
- If i Mod 2 > 0 Then
- Set Rng = .Cells(Int(i / 2) + 1, 1)
- Else
- Set Rng = .Cells(i - Int(i / 2), 3)
- End If
- Rng.Value = E
- With .Pictures.Insert(E)
- .Top = Rng.Cells(1, 2).Top
- .Left = Rng.Cells(1, 2).Left
- .Width = Rng.Cells(1, 2).Width
- .Height = Rng.Cells(1, 2).Height
- End With
- i = i + 1
- End If
- Next
- End With
- End Sub
複製代碼 |
|