应楼主MSN要求,略作完善,以下代码供参考: '* +++++++++++++++++++++++++++++
'* Created By 守柔(ShouRou)@ExcelHome 2005-2-19 19:48:57
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------Option Explicit
Sub GetGene()
Dim ExlApp As Excel.Application, ExlWb As Excel.Workbook, MyRange As Excel.Range, i As Excel.Range, LastRow As Long
Dim aWordRange As String, MyString As String, NewDoc As Document, TF As Boolean
On Error Resume Next '忽略错误
If Tasks.Exists("Microsoft Excel") = True Then '如果已打开EXCEL
TF = True: Set ExlApp = GetObject(, "Excel.Application") '直接调用该程序
Else
Set ExlApp = CreateObject("Excel.Application") '创建EXCEL程序
End If
With ExlApp
.Visible = False '隐藏程序
Set ExlWb = .Workbooks.Open("d:\li.xls") '请在此修改文件路径,注意盘符与反斜杠和后缀名
LastRow = ExlWb.Sheets(1).[A65536].End(xlUp).Row '取得A列最后一行数据的行号
Set MyRange = ExlWb.Sheets(1).Range("A1:A" & LastRow) '指定A列区域
For Each i In MyRange '在指定的A列中循环
'取得文本值并以段落标记分隔,是否需要分隔或者其它分隔符可以自行修改
aWordRange = i & "-" & i.Offset(, 1) & vbTab & ActiveDocument.Range(i - 1, i.Offset(, 1)).Text & vbCrLf
'累加文本值于内存中
MyString = MyString & aWordRange
Next
ExlWb.Close False '关闭并不保存指定工作薄
'如果本来就存在EXCEL程序则恢复正常显示反之退出程序
If TF = True Then .Visible = True Else Set ExlApp = Nothing
End With
Set NewDoc = Documents.Add '新建一个文档
Selection.InsertAfter MyString '插入内存中的文本
End Sub
'----------------------
Private Sub Document_Open()
On Error Resume Next
'以下引用EXCEL.EXE
ActiveDocument.VBProject.References.AddFromFile _
"C:\Program Files\Microsoft Office\Office" & Mid(Application.Version, 1, 2) & "\Excel.exe"
End Sub
'---------------------- |