返回列表 上一主題 發帖

[發問] 如何 插入 資料夾中含子資料夾的 圖片

回復 25# c_c_lai
謝謝:上了一課

TOP

回復 25# c_c_lai
Dim  f As Variant   這樣試試, 2007還有錯誤嗎?     

回復 27# whirlwind963
  1. Option Explicit
  2. Dim i As Integer, xCol As Integer
  3. Sub Ex()
  4.     Dim fs, f As Object, e As Object
  5.     Sheets(1).Activate
  6.     ActiveSheet.Pictures.Delete
  7.     Set fs = CreateObject("Scripting.FileSystemObject").GetFolder("D:\2012-12-12")
  8.     xCol = 3    '欄數
  9.     For Each e In fs.subfolders     '資料夾集合物件
  10.         i = 1                       '列數
  11.         子資料夾 e
  12.         xCol = xCol + 1             '欄數
  13.     Next
  14. End Sub
  15. Private Sub 子資料夾(資料夾 As Variant)
  16.     Dim fs  As Object, f As Variant
  17.     Set fs = CreateObject("Scripting.FileSystemObject").GetFolder(資料夾)
  18.     For Each f In fs.Files    '檔案:集合物件
  19.         If UCase(f) Like "*.JPG" Or UCase(f) Like "*.GIF" Or UCase(f) Like "*.BMP" Then
  20.             i = i + 1
  21.             With ActiveSheet.Pictures.Insert(f)
  22.                 .Top = Cells(i, xCol).Top
  23.                 .Left = Cells(i, xCol).Left
  24.                 .Height = 49.5
  25.                 .Width = 49.5
  26.                 Cells(i, xCol).RowHeight = .Height
  27.                 Cells(i, xCol).ColumnWidth = .Width / 5.5
  28.             End With
  29.         End If
  30.     Next
  31.     For Each f In fs.subfolders     '資料夾:集合物件
  32.         i = i + 1
  33.         子資料夾 f                  '再度呼叫 (本程序)
  34.     Next
  35. End Sub
複製代碼

TOP

回復 29# whirlwind963
是一樣的: 這引數 TheFolder 沒宣告型態 就是  As Variant
  1. Variant 資料型態
  2. Variant 資料型態是所有沒被明確宣告為其他型
複製代碼

TOP

        靜思自在 : 手心向下是助人,手心向上是求人;助人快樂,求人痛苦。
返回列表 上一主題