如果改成
NN= cells(2,1)
MM=cells(3,1)
For Each e In Array(NN,MM)
Set fs = CreateObject("Scripting.FileSystemObject").GetFolder(e)
子資料夾 fs
Next
會出錯
請問有辦法自己在儲存格輸入位址嗎作者: GBKEE 時間: 2012-11-3 15:06
With ActiveSheet.Pictures.Insert(e & "\" & f.Name)
複製代碼
如此看來,For Each f In e.Files 的 f 在 2003 它可以當成字串直接處理,
而在 2010 時, f 則視為一個物件 (Class),此時如果直接使用它執行
With ActiveSheet.Pictures.Insert(f) 就會出現 1004 的錯誤訊息。作者: GBKEE 時間: 2012-12-13 15:03
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
複製代碼
作者: whirlwind963 時間: 2012-12-15 11:17
回復 28#GBKEE
我看懂了~
感謝~
跟4#的程式碼差了一點
Private Sub 子資料夾(TheFolder)
Dim fs As Object, f As Object
Set fs = CreateObject("Scripting.FileSystemObject").GetFolder(TheFolder)
=========================================================
Private Sub 子資料夾(資料夾 As Variant)
Dim fs As Object, f As Variant
Set fs = CreateObject("Scripting.FileSystemObject").GetFolder(資料夾)
可以請問上面跟下面的差別嗎作者: GBKEE 時間: 2012-12-15 11:35
回復 29#whirlwind963
是一樣的: 這引數 TheFolder 沒宣告型態 就是 As Variant