ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > 我的测验 > Excel VBA > 出题:开发一个选区、图形导入批注的宏

出题:开发一个选区、图形导入批注的宏

作者:绿色风 分类: 时间:2022-08-18 浏览:132
楼主
罗刚君
1.如果选择单元格,将另一个选区导入当前单元格批注中
2.如果选择图形对象,将图形对象导入活动单元格批注中
3.用快捷键“Ctrl+Q”调用
完成以上功能加分图片与批注.gif
 
2楼
fāi
加分题 我试试

图片批注(fāi).rar
3楼
fāi
图像质量…… 期待罗老师的……

  1. Sub 图片批注()
  2.     Application.ScreenUpdating = False
  3.     On Error Resume Next
  4.     s = ActiveCell.Address
  5.     t = ActiveSheet.Shapes.Count
  6.     Selection.Copy
  7.     ActiveSheet.Paste
  8.     If ActiveSheet.Shapes.Count = t Then
  9.         Application.CutCopyMode = False
  10.         Application.ScreenUpdating = True
  11.         Set rs = Application.InputBox("请选择区域", "区域", s, Type:=8)
  12.         If rs.Address = Empty Then Exit Sub
  13.         Set r = Range(rs.Address)
  14.         Application.ScreenUpdating = False
  15.         r.CopyPicture Appearance:=xlScreen, Format:=xlPicture
  16.         ActiveSheet.Paste
  17.     End If
  18.     Set Shp = ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
  19.     fn = ThisWorkbook.Path & "\" & Shp.Name & ".jpg"
  20.     Shp.Copy
  21.     With ActiveSheet.ChartObjects.Add(0, 0, Shp.Width, Shp.Height + 6).Chart
  22.         .Paste
  23.         .Export fn, "jpg"
  24.         .Parent.Delete
  25.     End With
  26.     Range(s).Select
  27.     Range(s).ClearComments
  28.     With Range(s).AddComment
  29.         .Visible = True
  30.         .Text Text:=""
  31.         .Shape.Width = Shp.Width
  32.         .Shape.Height = Shp.Height
  33.         .Shape.Select True
  34.         Selection.ShapeRange.Fill.UserPicture fn
  35.         .Visible = False
  36.     End With
  37.     Shp.Delete
  38.     Kill fn
  39.     Application.ScreenUpdating = True
  40. End Sub

4楼
罗刚君
终于有人回答我的问题了
加个支持分
不过答案中有两个问题:
1.清晰度不够
2.变形
3.产生了后遗症,工作表中多出个图片
望改进
5楼
fāi

  1. Private Declare Function OpenClipboard Lib "User32" _
  2.                                        (ByVal hWnd As Long) As Long
  3. Private Declare Function CloseClipboard Lib "User32" () As Long
  4. Private Declare Function GetClipboardData Lib "User32" _
  5.                                           (ByVal uFormat As Long) As Long
  6. Private Declare Function CopyEnhMetaFileA Lib "Gdi32" _
  7.                                           (ByVal hemfSrc As Long, ByVal lpszFile As String) As Long
  8. Private Declare Function DeleteEnhMetaFile Lib "Gdi32" _
  9.                                            (ByVal hdc As Long) As Long
  10. Sub 图片批注()
  11.     s = ActiveCell.Address: f = ThisWorkbook.Path & "\pz.JPG"
  12.     If TypeName(Selection) = "Range" Then
  13.         Set rs = Application.InputBox("请选择区域", "区域", s, Type:=8)
  14.         If rs.Address = Empty Then Exit Sub
  15.         Application.ScreenUpdating = False
  16.         Range(rs.Address).CopyPicture
  17.         ActiveSheet.Paste
  18.         Set Shp = ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
  19.         w = Shp.Width: h = Shp.Height
  20.         Selection.Delete
  21.     ElseIf TypeName(Selection) = "Picture" Then
  22.         Application.ScreenUpdating = False
  23.         Selection.CopyPicture
  24.         Set Shp = ActiveSheet.Shapes(Selection.Name)
  25.         w = Shp.Width: h = Shp.Height
  26.     Else
  27.         Exit Sub
  28.     End If
  29.     OpenClipboard 0
  30.     DeleteEnhMetaFile CopyEnhMetaFileA(GetClipboardData(14), f)
  31.     CloseClipboard
  32.     Application.CutCopyMode = False
  33.     Range(s).Select
  34.     Range(s).ClearComments
  35.     With Range(s).AddComment
  36.         .Visible = True
  37.         .Text Text:=""
  38.         .Shape.Width = w
  39.         .Shape.Height = h
  40.         .Shape.Select True
  41.         Selection.ShapeRange.Fill.UserPicture f
  42.         .Visible = False
  43.     End With
  44.     Kill f
  45.     Application.ScreenUpdating = True
  46.     Set Shp = Nothing
  47. End Sub
6楼
fāi
空闲再做了一下
不知是否符合要求
请明示

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap