- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
2#
發表於 2014-4-24 05:25
| 只看該作者
本帖最後由 GBKEE 於 2014-4-24 05:26 編輯
回復 1# xlarge16803 - Option Explicit
- Sub 載入圖片()
- Dim MyRng As Range, XR As Range, uPath$, y&, xFile$
- Set MyRng = [A3]
- If [A3] = "" Then MsgBox "無圖檔名稱!": Exit Sub
- 'ThisWorkbook.Path 傳回這活頁簿檔案存檔的路徑 如 ="C:\"
- uPath = ThisWorkbook.Path & "c:/my picture/" ' =>"C:\c:/my picture/" 這是錯誤的路徑?
- '是這樣吧!!
- uPath = ThisWorkbook.Path '->= "c:/my picture" 對嗎???
- If Dir(uPath, vbDirectory) = "" Then MsgBox "找不到圖檔資料夾!": Exit Sub
- ActiveSheet.Pictures.Delete
- Application.ScreenUpdating = False
- For Each XR In Union([B3], [C3], [D3], [E3])
- y = y + 1
- xFile = uPath & "\" & MyRng & "-" & y & ".JPG"
- If Dir(xFile) <> "" Then
- With ActiveSheet.Pictures.Insert(xFile)
- .ShapeRange.LockAspectRatio = msoFalse
- .Width = XR.Width
- .Height = XR.Height
- .Left = XR.Left
- .Top = XR.Top
- End With
- End If
- Next
- End Sub
複製代碼 |
|