Set xlbook2 = xlapp.Workbooks.Open(tarFile)这句报错,求大神帮忙!! 10
DimxlappAsExcel.ApplicationDimxlbook1AsExcel.WorkbookDimxlbook2AsExcel.WorkbookDimxls...
Dim xlapp As Excel.Application
Dim xlbook1 As Excel.Workbook
Dim xlbook2 As Excel.Workbook
Dim xlsheet1 As Excel.Worksheet
Dim xlsheet2 As Excel.Worksheet
Sub CommonButton1_click()
Set xlapp = CreateObject("Excel.Application")
Set xlbook1 = xlapp.Workbooks.Open("G:\intern\xsb\research\line.xlsx")
Set xlsheet1 = xlbook1.Worksheets(3)
Dim name As String
Dim tarFile As String
Dim m As Integer
For i = 2 To 80
name = xlsheet1.Cells(i, 1)'这个sheet的第一列是文件名列表
tarFile = "G:\intern\xsb\research\one\" + name + ".xlsx"
Set xlbook2 = xlapp.Workbooks.Open(tarFile)‘这句报错,错误提示运行时错误1004:应用程序定义或对象定义错误
xlapp.Visible = True
Set xlsheet2 = xlbook2.Worksheets(1)
m = xlsheet1.Cells(i, 5)
Set Rng = xl.ActiveSheet.UsedRange
For j = 2 To Rng.Rows.Count
If xlsheet2.Cells(j, 3) >= xlsheet1.Cells(i, 4) Then
If xlsheet2.Cells(j, 4) > m Then
m = xlsheet2.Cells(j, 4)
End If
End If
Next j
xlsheet1.Cells(i, 6) = m
Next i
End Sub 展开
Dim xlbook1 As Excel.Workbook
Dim xlbook2 As Excel.Workbook
Dim xlsheet1 As Excel.Worksheet
Dim xlsheet2 As Excel.Worksheet
Sub CommonButton1_click()
Set xlapp = CreateObject("Excel.Application")
Set xlbook1 = xlapp.Workbooks.Open("G:\intern\xsb\research\line.xlsx")
Set xlsheet1 = xlbook1.Worksheets(3)
Dim name As String
Dim tarFile As String
Dim m As Integer
For i = 2 To 80
name = xlsheet1.Cells(i, 1)'这个sheet的第一列是文件名列表
tarFile = "G:\intern\xsb\research\one\" + name + ".xlsx"
Set xlbook2 = xlapp.Workbooks.Open(tarFile)‘这句报错,错误提示运行时错误1004:应用程序定义或对象定义错误
xlapp.Visible = True
Set xlsheet2 = xlbook2.Worksheets(1)
m = xlsheet1.Cells(i, 5)
Set Rng = xl.ActiveSheet.UsedRange
For j = 2 To Rng.Rows.Count
If xlsheet2.Cells(j, 3) >= xlsheet1.Cells(i, 4) Then
If xlsheet2.Cells(j, 4) > m Then
m = xlsheet2.Cells(j, 4)
End If
End If
Next j
xlsheet1.Cells(i, 6) = m
Next i
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询