'楼主只上传了一个工作表,只以代码假设其他工作与这个工作表类似 '在运行前需添加对Microsoft Excel Object Library 的引用 Sub main() '主程序 Dim myAppExcel As New Excel.Application Dim mySheet As Worksheet If Not myAppExcel.Dialogs(xlDialogOpen).Show Then Exit Sub End If For Each mySheet In myAppExcel.ActiveWorkbook.Sheets myAppExcel.Range(mySheet.Cells(1, 1), mySheet.Cells.SpecialCells(xlCellTypeLastCell)).Copy '对数据区复制 PasteToWord Next myAppExcel.Quit End Sub
Sub PasteToWord() Dim myDoc As Document, myRange As Range, myTable As Table Set myDoc = Documents.Add myDoc.Content.PasteAndFormat wdFormatPlainText '以文本方式粘贴 '以下代码将文字转化为表格 Set myRange = myDoc.Content Do While myRange.Find.Execute(FindText:="日期*^13*^13", Forward:=True, _ Format:=False, Wrap:=wdFindStop, MatchWildcards:=True) Set myTable = myRange.ConvertToTable(Separator:=wdSeparateByTabs, NumColumns:=17, _ NumRows:=2, AutoFitBehavior:=wdAutoFitFixed) setTable myTable Set myRange = ActiveDocument.Content 'myRange需重新定义 Loop '以下代码删除文档中多余的制表位 Set myRange = myDoc.Content With myRange.Find .ClearFormatting .Text = "^t{2,}" |