|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
请学会搜索,谢谢! 以下代码供参考 '* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-9-11 16:36:41
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'№ 00015^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------Option Explicit
'请在VBE/工具(T)/引用(R)中勾选对于"MICROSOFT EXCEL 10.0 OBJECT LIBRARY的引用
Sub GetExcApp()
Dim xlObj As Excel.Application, xlWb As Excel.Workbook, TF As Boolean
Dim i As Excel.Range
On Error Resume Next '忽略错误
'如果任务栏中有Excel程序则调用该现有程序,反之则创建一个新的EXCEL程序
If Tasks.Exists("Microsoft Excel") = True Then
Set xlObj = GetObject(, "Excel.Application")
Else
Set xlObj = CreateObject("Excel.Application")
TF = True
End If
Set xlWb = xlObj.Workbooks.Open("E:\Example.xls") '打开指定的工作薄
For Each i In xlWb.Sheets(1).Range("A1:C3")
With ActiveDocument.Tables(1)
.Cell(i.Row, i.Column).Range = i.Value
End With
Next
xlWb.Close '关闭工作薄
If TF = False Then Exit Sub
xlObj.Quit '关闭Excel进程
Set xlObj = Nothing '释放对象变量
End Sub
'---------------------- |
|