Dim oExcel As excel.Workbook
Set oExcel = Df1.ActiveDocument
Err.Clear
oExcel.Application.DisplayAlerts = False
oExcel.Application.Cells.Find(what:=strSName, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Activate
If Err.Number = 0 Then
oExcel.Application.ActiveSheet.Paste
End If
Clipboard.Clear
oExcel.Application.Quit
Set oExcel = Nothing
Set oExcel = Df1.ActiveDocument
Err.Clear
oExcel.Application.DisplayAlerts = False
oExcel.Application.Cells.Find(what:=strSName, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Activate
If Err.Number = 0 Then
oExcel.Application.ActiveSheet.Paste
End If
Clipboard.Clear
oExcel.Application.Quit
Set oExcel = Nothing
这一行出错
Dim xlBook as Excel.WorkBook
Dim xlSheet as Excel.WorkSheet
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open("xls_Path") '指明Workbook的路径
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Activate
Err.Clear
xlBook.Application.DisplayAlerts = False
自己写了个程序用xlBook.Application.DisplayAlerts = False,没有出错。
把变量都声明全了,指明Workbook的路径,就不会有错。
绝对路径 自己的写路径