作者:绿色风
分类:
时间:2022-08-17
浏览:181
楼主 wise |
Q:如何把Excel工作表中的所有批注内容输出到word中? A:ALT+F11→插入模块→模块中输入以下代码:
- Sub PrintCellComments()
- Dim Cmt As String
- Dim C As Range
- Dim I As Integer
- Dim WordObj As Object
- Dim ws As Worksheet
- Dim PrintValue As Boolean
- Dim res As Integer
- On Error Resume Next
- Err.Number = 0
- res = MsgBox("你想把单元格中的批注内容输出来么?", _
- vbYesNoCancel + vbQuestion, "请输出单元格中的批注内容")
- Select Case res
- Case vbCancel
- Exit Sub
- Case vbYes
- PrintValue = True
- Case Else
- PrintValue = False
- End Select
- Set WordObj = GetObject(, "Word.Application")
- If Err.Number = 429 Then
- Set WordObj = CreateObject("Word.Application")
- Err.Number = 0
- End If
- WordObj.Visible = True
- WordObj.Documents.Add
- With WordObj.Selection
- .TypeText Text:="工作簿: " + ActiveWorkbook.Name
- .TypeParagraph
- .TypeText Text:="输出时间: " + Format(Now(), "dd-mm-yyyy hh:mm")
- .TypeParagraph
- .TypeParagraph
- End With
- For Each ws In Worksheets
- For I = 1 To ws.Comments.Count
- Set C = ws.Comments(I).Parent
- Cmt = ws.Comments(I).Text
- With WordObj.Selection
- .TypeText Text:="批注所在单元格: " + _
- C.Address(False, False, xlA1) + " 所在工作表: " + ws.Name
- If PrintValue = True Then
- .TypeText Text:=" 单元格中的内容: " + Format(C.Value)
- End If
- .TypeParagraph
- .TypeText Text:=Cmt
- .TypeParagraph
- .TypeParagraph
- End With
- Next I
- Next ws
- Set WordObj = Nothing
- MsgBox "完成批注输出到Word", vbInformation, _
- "输出批注内容"
- End Sub
我的论坛.rar |
2楼 kevinchengcw |
不错,收下了 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一