|
文件夹地址放在单元格C1里面,代码放在Sheet1下
- Private Sub Worksheet_Change(ByVal Target As Range)
- 'VarFileName = Application.GetOpenFilename("All Files (*.*), *.*", MultiSelect:=False)
- 'VarFileNameArr = Split(VarFileName, "")
- 'n = UBound(VarFileNameArr)
- 'Debug.Print n, VarFileNameArr(n)
- 'l = Len(VarFileNameArr(n))
- 'FilePath = Left(VarFileName, Len(VarFileName) - Len(VarFileNameArr(n)))
-
- Set tmpRange = ThisWorkbook.Sheets("Sheet1").Range("B1")
- Application.ScreenUpdating = False
- t = tmpRange.Top
- l = tmpRange.Left
- h = tmpRange.Offset(tmpRange.Rows.Count, 0).Top - tmpRange.Top
- w = tmpRange.Offset(0, tmpRange.Columns.Count).Left - tmpRange.Left
- On Error GoTo ErrTrap
- Debug.Print tmpRange.Parent.Name
- Set p = tmpRange.Parent.Pictures.Insert(Range("C1").Value & "" & Range("A1").Value & ".JPG")
- With p
- .Top = t
- .Left = l
- .Height = h
- .Width = w
- End With
- Set tmpRange = Nothing
- Set p = Nothing
- exitsub:
- Application.ScreenUpdating = True
- Exit Sub
- ErrTrap:
- Application.ScreenUpdating = True
- ErrNumber = Err.Number
- If ErrNumber = 1004 Then
- MsgBox "The file selected is not a valid picture!", vbInformation
- End If
- Set tmpRange = Nothing
- Set p = Nothing
- GoTo exitsub
- End Sub
复制代码 |
|