- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
28#
發表於 2012-12-15 10:56
| 只看該作者
回復 25# c_c_lai
Dim f As Variant 這樣試試, 2007還有錯誤嗎?
回復 27# whirlwind963 - Option Explicit
- Dim i As Integer, xCol As Integer
- Sub Ex()
- Dim fs, f As Object, e As Object
- Sheets(1).Activate
- ActiveSheet.Pictures.Delete
- Set fs = CreateObject("Scripting.FileSystemObject").GetFolder("D:\2012-12-12")
- xCol = 3 '欄數
- For Each e In fs.subfolders '資料夾集合物件
- i = 1 '列數
- 子資料夾 e
- xCol = xCol + 1 '欄數
- Next
- End Sub
- Private Sub 子資料夾(資料夾 As Variant)
- Dim fs As Object, f As Variant
- Set fs = CreateObject("Scripting.FileSystemObject").GetFolder(資料夾)
- For Each f In fs.Files '檔案:集合物件
- If UCase(f) Like "*.JPG" Or UCase(f) Like "*.GIF" Or UCase(f) Like "*.BMP" Then
- i = i + 1
- With ActiveSheet.Pictures.Insert(f)
- .Top = Cells(i, xCol).Top
- .Left = Cells(i, xCol).Left
- .Height = 49.5
- .Width = 49.5
- Cells(i, xCol).RowHeight = .Height
- Cells(i, xCol).ColumnWidth = .Width / 5.5
- End With
- End If
- Next
- For Each f In fs.subfolders '資料夾:集合物件
- i = i + 1
- 子資料夾 f '再度呼叫 (本程序)
- Next
- End Sub
複製代碼 |
|