- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
本帖最後由 GBKEE 於 2012-12-5 11:17 編輯
回復 1# a703130 - Option Explicit
- Sub Ex() '判斷資料夾內是否有檔案
- 'Dir("D:\test\*.PNG") = "" 為資料夾中檔案沒有副檔名是PNG的檔案
- '判斷資料夾中檔案是否有關鍵字 ".PNG & .JPG"
- If Dir("D:\test\*.PNG") = "" And Dir("D:\test\*.JPG") = "" Then MsgBox "資料夾中沒有 .PNG .JPG"
- End Sub
複製代碼 整理一下你的程式碼- Option Explicit
- Sub InsertImage(ImagePath, FolderName)
- Dim ReadRow As Integer, ImageName As String
- Sheets("a").Select
- ReadRow = 24
- '判斷Safety頁面第一欄是否有需要載入圖檔直至出現"END"字樣
- Do Until UCase(Cells(ReadRow, 1)) = "END"
- 'ImageName = Cells(ReadRow, 1)
- ImageName = ImagePath & "\" & FolderName & "\" & Cells(ReadRow, 1)
- If InStr(ImageName, ".PNG") Or InStr(ImageName, ".JPG") Then
- If Dir(ImageName) <> "" Then
- Cells(ReadRow, 2).Select
- ActiveSheet.Pictures.Insert(ImageName).Select
- Call ImageSize
- End If
- End If
- ReadRow = ReadRow + 1
- Loop
- End Sub
複製代碼 |
|