|
楼主 |
发表于 2014-8-3 12:08
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
zjdh 发表于 2014-8-3 09:26
Private Sub CommandButton1_Click()
On Error Resume Next ...
老师,我在论坛搜到一个帖子,应该是和我遇到的情况差不多,他说:
“我之前是使用ActiveSheet.Pictures.Insert(Fullfilepath).Select 插入的,这个是使用录制宏中的代码,在2010中保存不了,现在改成
Application.Dialogs(xlDialogInsertPicture).Show 可以保存了!”
可是我看不懂,我把改前改后的表格测试了一下,确实解决了这个不能保存图片的问题,原VBA是:
Sub insertPic()
Dim i As Integer
Dim path As String
Dim rng As Range
Dim s As String
Dim filename As String
With Sheet1
path = ThisWorkbook.path
ChDir (path)
For i = 2 To .Range("b65536").End(xlUp).Row
filename = Dir(ThisWorkbook.path & "\*" & Cells(i, 2).Text & "*.jpg")
If filename <> "" Then
.Pictures.Insert(path & "\" & filename).Select
Set rng = .Cells(i, 1)
With Selection
.Top = rng.Top + 1
.Left = rng.Left + 1
.Width = rng.Width - 1
.Height = rng.Height - 1
End With
Else
s = s & Chr(10) & .Cells(i, 2).Text
End If
Next
.Cells(2, 1).Select
End With
If s <> "" Then
MsgBox s & Chr(10) & "没有照片!"
End If
End Sub
改后的VBA是:
Sub insertPic()
Dim i As Integer
Dim path As String
Dim shpPic As Shape
Dim rng As Range
Dim s As String
Dim filename As String
With Sheet1
path = ThisWorkbook.path
ChDir (path)
For i = 2 To .Range("b65536").End(xlUp).Row
filename = Dir(ThisWorkbook.path & "\*" & Cells(i, 2).Text & "*.jpg")
If filename <> "" Then
Set rng = .Cells(i, 1)
Set shpPic = ActiveSheet.Shapes.AddPicture(path & "\" & filename, msoFalse, msoTrue, rng.Left + 1, rng.Top + 1, -1, -1)
Else
s = s & Chr(10) & .Cells(i, 2).Text
End If
Next
.Cells(2, 1).Select
End With
If s <> "" Then
MsgBox s & Chr(10) & "没有照片!"
End If
End Sub
麻烦老师也给我诊断一下!非常感谢! |
|