|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
看楼主急的这样,来段代码,仅供参考,稍作修改即可使用:
- Sub Insert_Picture()
- FileName = Application.GetOpenFilename
- Set tmpRange = Application.InputBox("Please select one cell to insert the picture!", Type:=8)
- 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(FileName)
- 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
复制代码 |
|