Sub 載入圖片()
Dim MyRng As Range, xR As Range, uPath$, y&, xFile$
Set MyRng = [A3]
If [A3] = "" Then MsgBox "無圖檔名稱!": Exit Sub
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 GoTo 101
With ActiveSheet
.Pictures.Insert (xFile)
With .Shapes(.Shapes.Count)
.LockAspectRatio = msoFalse
.Width = xR.Width
.Height = xR.Height
.Left = xR.Left
.Top = xR.Top
End With
End With
101: Next
End Sub作者: GBKEE 時間: 2014-4-24 05:25
抱歉!!
附上程式碼..
我想在公司用這個程式 路徑圖是\\178.153.85\fast\品質管理G\ 是否也可以抓圖
非常感謝大大 解答
Sheets("Sheet1").Select
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.P2ctures.Delete
Sheets("Sheet1").Select
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