|
楼主 |
发表于 2014-8-6 00:19
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 lk710618 于 2014-8-6 00:26 编辑
zjdh 发表于 2014-8-5 18:56
Private Sub CommandButton1_Click()
On Error Resume Next
Dim rngTemp As Range, k As Range, ...
老师我不太懂VBA,这次学习到很多内容,感触也很深,谢谢你!很迷茫的一点是,虽然照搬来老师们的很多好的代码,可是很多实在是看不懂,真不知如何入手学习
老师,我又参考别人的资料,把控件合二为一了,测试了一下,很好用
Private Sub CommandButton1_Click()
With CommandButton1
If .Caption = "删除" Then
ActiveSheet.Range("A:ZZ").ClearComments '删除选区内的批注
For Each shp In ActiveSheet.Shapes
If Not shp.Type = msoOLEControlObject Then shp.Delete
Next
.Caption = "插入"
.BackColor = &HFFFF& '按钮黄色
Exit Sub
End If
If .Caption = "插入" Then
On Error Resume Next
Dim rngTemp As Range, k As Range, shpPic As Picture
Set rngTemp = Application.InputBox("图片插入区域:", "选择单元格", Type:=8)
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = -1 Then
FilePath = fd.SelectedItems(1) & "\"
Else
Exit Sub
End If
For Each k In rngTemp
With k
Filename = Dir(FilePath & .Value & "*.jpg")
If k <> "" And Filename <> "" Then
ActiveSheet.Shapes.Addpicture FilePath & Filename, False, True, .Left, .Top, .Width, .Height
.ClearComments
.AddComment
.Comment.Shape.Fill.UserPicture FilePath & "\" & .Value & ".jpg"
.Comment.Shape.Height = 240
.Comment.Shape.Width = 320
Filename = ""
End If
End With
Next
ActiveSheet.Shapes.SelectAll
Selection.Placement = xlMoveAndSize
Range("A1").Select
.Caption = "删除"
.BackColor = &HFF& '按钮红色
Exit Sub
End If
End With
End Sub
好东西,继续分享!
|
|