返回列表 上一主題 發帖

[發問] 判斷資料夾內是否有檔案

本帖最後由 GBKEE 於 2012-12-5 11:17 編輯

回復 1# a703130
  1. Option Explicit
  2. Sub Ex() '判斷資料夾內是否有檔案
  3.     'Dir("D:\test\*.PNG") = "" 為資料夾中檔案沒有副檔名是PNG的檔案
  4.     '判斷資料夾中檔案是否有關鍵字 ".PNG & .JPG"
  5.     If Dir("D:\test\*.PNG") = "" And Dir("D:\test\*.JPG") = "" Then MsgBox "資料夾中沒有 .PNG  .JPG"
  6. End Sub
複製代碼
整理一下你的程式碼
  1. Option Explicit
  2. Sub InsertImage(ImagePath, FolderName)
  3.     Dim ReadRow As Integer, ImageName As String
  4.     Sheets("a").Select
  5.     ReadRow = 24
  6.     '判斷Safety頁面第一欄是否有需要載入圖檔直至出現"END"字樣
  7.     Do Until UCase(Cells(ReadRow, 1)) = "END"
  8.         'ImageName = Cells(ReadRow, 1)
  9.         ImageName = ImagePath & "\" & FolderName & "\" & Cells(ReadRow, 1)
  10.         If InStr(ImageName, ".PNG") Or InStr(ImageName, ".JPG") Then
  11.             If Dir(ImageName) <> "" Then
  12.                 Cells(ReadRow, 2).Select
  13.                 ActiveSheet.Pictures.Insert(ImageName).Select
  14.                 Call ImageSize
  15.             End If
  16.         End If
  17.         ReadRow = ReadRow + 1
  18.     Loop
  19. End Sub
複製代碼

TOP

        靜思自在 : 【時間無法遮擋】怕時間消逝,花了許多心血,想盡各式方法要遮擋時間,結果是:浪費了更多時間,且一無所成!
返回列表 上一主題