ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > E问E答 > Excel VBA > 如何运用VBA将工作表中的批注中的图片导出指定的文件夹中存放?

如何运用VBA将工作表中的批注中的图片导出指定的文件夹中存放?

作者:绿色风 分类: 时间:2022-08-17 浏览:171
楼主
xmyjk
Q:将工作表中的批注中的图片导出指定的文件夹中存放

A:方法一:
  1. Option Explicit
  2. Private Declare Function OpenClipboard Lib "User32" (ByVal hWnd As Long) As Long
  3. Private Declare Function CloseClipboard Lib "User32" () As Long
  4. Private Declare Function GetClipboardData Lib "User32" (ByVal uFormat As Long) As Long
  5. Public Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long

  6. Private Type GUID
  7.     Data1 As Long
  8.     Data2 As Integer
  9.     Data3 As Integer
  10.     Data4(0 To 7) As Byte
  11. End Type

  12. Private Type PicBmp
  13.     Size As Long
  14. Type As Long
  15.     hBmp As Long
  16.     hPal As Long
  17.     Reserved As Long
  18. End Type

  19. Sub t()
  20.     Dim rng As Range, flnm As String, Pic As PicBmp, IPic As IPicture, IID_IDispatch As GUID
  21.     For Each rng In Sheet1.Cells.SpecialCells(xlCellTypeComments)
  22.         If rng.Comment.Shape.Fill.Type = msoFillPicture Then
  23.             flnm = ThisWorkbook.Path & "\" & rng.Value & ".bmp"
  24.             With rng.Comment
  25.                 .Visible = True
  26.                 .Shape.CopyPicture 1, 2
  27.                 .Visible = False
  28.             End With
  29.             OpenClipboard 0
  30.             With IID_IDispatch
  31.                 .Data1 = &H20400
  32.                 .Data4(0) = &HC0
  33.                 .Data4(7) = &H46
  34.             End With
  35.             With Pic
  36.                 .Size = Len(Pic)
  37.                 .Type = 1
  38.                 .hBmp = GetClipboardData(2)
  39.             End With
  40.             OleCreatePictureIndirect Pic, IID_IDispatch, 1, IPic
  41.             stdole.SavePicture IPic, flnm
  42.             CloseClipboard
  43.         End If
  44.     Next
  45. End Sub
方法二
  1. Option Explicit
  2. Private Declare Function OpenClipboard Lib "User32" (ByVal hWnd As Long) As Long
  3. Private Declare Function CloseClipboard Lib "User32" () As Long
  4. Private Declare Function GetClipboardData Lib "User32" (ByVal uFormat As Long) As Long
  5. Private Declare Function CopyEnhMetaFileA Lib "Gdi32" (ByVal hemfSrc As Long, ByVal lpszFile As String) As Long
  6. Private Declare Function DeleteEnhMetaFile Lib "Gdi32" (ByVal hdc As Long) As Long

  7. Sub t()
  8.     Dim rng As Range, flnm As String

  9.     For Each rng In Sheet1.Cells.SpecialCells(xlCellTypeComments)
  10.         If rng.Comment.Shape.Fill.Type = msoFillPicture Then
  11.             flnm = ThisWorkbook.Path & "\" & rng.Value & ".JPG"
  12.             With rng.Comment
  13.                 .Visible = True
  14.                 .Shape.CopyPicture xlScreen, xlPicture
  15.                 .Visible = False
  16.             End With
  17.             OpenClipboard 0
  18.             DeleteEnhMetaFile CopyEnhMetaFileA(GetClipboardData(14), flnm)
  19.             CloseClipboard
  20.         End If
  21.     Next
  22. End Sub

另存批注图片.rar
另存批注图片1.zip
2楼
hylees
学习
3楼
eliane_lei
向楼主学习!
4楼
老糊涂


免责声明

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

评论列表
sitemap