ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > E问E答 > Excel VBA > 如何把Excel工作表中的所有批注内容输出到word中?

如何把Excel工作表中的所有批注内容输出到word中?

作者:绿色风 分类: 时间:2022-08-17 浏览:181
楼主
wise
Q:如何把Excel工作表中的所有批注内容输出到word中?
A:ALT+F11→插入模块→模块中输入以下代码:

  1. Sub PrintCellComments()
  2. Dim Cmt As String
  3. Dim C As Range
  4. Dim I As Integer
  5. Dim WordObj As Object
  6. Dim ws As Worksheet
  7. Dim PrintValue As Boolean
  8. Dim res As Integer
  9. On Error Resume Next
  10. Err.Number = 0
  11. res = MsgBox("你想把单元格中的批注内容输出来么?", _
  12.     vbYesNoCancel + vbQuestion, "请输出单元格中的批注内容")
  13. Select Case res
  14.     Case vbCancel
  15.         Exit Sub
  16.     Case vbYes
  17.         PrintValue = True
  18.     Case Else
  19.         PrintValue = False
  20. End Select
  21. Set WordObj = GetObject(, "Word.Application")
  22. If Err.Number = 429 Then
  23.     Set WordObj = CreateObject("Word.Application")
  24.     Err.Number = 0
  25. End If
  26. WordObj.Visible = True
  27. WordObj.Documents.Add
  28. With WordObj.Selection
  29. .TypeText Text:="工作簿: " + ActiveWorkbook.Name
  30. .TypeParagraph
  31. .TypeText Text:="输出时间: " + Format(Now(), "dd-mm-yyyy hh:mm")
  32. .TypeParagraph
  33. .TypeParagraph
  34. End With
  35. For Each ws In Worksheets
  36.     For I = 1 To ws.Comments.Count
  37.         Set C = ws.Comments(I).Parent
  38.         Cmt = ws.Comments(I).Text
  39.         With WordObj.Selection
  40.         .TypeText Text:="批注所在单元格: " + _
  41.             C.Address(False, False, xlA1) + " 所在工作表: " + ws.Name
  42.         If PrintValue = True Then
  43.             .TypeText Text:=" 单元格中的内容: " + Format(C.Value)
  44.         End If
  45.         .TypeParagraph
  46.         .TypeText Text:=Cmt
  47.         .TypeParagraph
  48.         .TypeParagraph
  49.         End With
  50.     Next I
  51. Next ws
  52. Set WordObj = Nothing
  53. MsgBox "完成批注输出到Word", vbInformation, _
  54.     "输出批注内容"
  55. End Sub



我的论坛.rar
2楼
kevinchengcw
不错,收下了

免责声明

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

评论列表
sitemap