vb打开excel文件出错,求指教!错误指在“Set xlbook = xlapp.Workbooks.Open(myfilename)”这句~
DimxlappAsExcel.ApplicationDimxlbookAsExcel.WorkbookDimxlsheetAsExcel.WorksheetDimmyf...
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim myfilename As String
dim number as interger
Private Sub Form_Load()
If PathFileExists("F:\data") = 0 Then MkDir "F:\data" '如果文件夹不存在,则新建文件夹
myfilename = "F:\data\" + Trim(Str(Year(Now))) + Trim(Str(Month(Now))) + Trim(Str(Day(Now))) + ".xls"
If PathFileExists(myfilename) = 0 Then
Set xlapp = New Excel.Application '创建EXCEL对象
xlapp.Workbooks.add
xlapp.Rows(1).Font.Name = "黑体"
xlapp.Rows(1).Font.Size = 20
xlapp.Range("A1:C1") = Array("时间", "温度", "水位")
xlapp.ActiveWorkbook.SaveAs myfilename
xlapp.Quit
number = 2
Else '如果文件存在,则打开文件,并找到已写入的数据的末尾位置
xlapp.Workbooks.Open(myfilename)
Dim i As Integer
For i = 1 To 5000
If xlapp.Cells(i, 1) = "" Then
number = i
Exit For
End If
Next i
xlapp.Quit
End If
End Sub
错误是:实时错误91,对象变量或with块变量未设置~ 展开
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim myfilename As String
dim number as interger
Private Sub Form_Load()
If PathFileExists("F:\data") = 0 Then MkDir "F:\data" '如果文件夹不存在,则新建文件夹
myfilename = "F:\data\" + Trim(Str(Year(Now))) + Trim(Str(Month(Now))) + Trim(Str(Day(Now))) + ".xls"
If PathFileExists(myfilename) = 0 Then
Set xlapp = New Excel.Application '创建EXCEL对象
xlapp.Workbooks.add
xlapp.Rows(1).Font.Name = "黑体"
xlapp.Rows(1).Font.Size = 20
xlapp.Range("A1:C1") = Array("时间", "温度", "水位")
xlapp.ActiveWorkbook.SaveAs myfilename
xlapp.Quit
number = 2
Else '如果文件存在,则打开文件,并找到已写入的数据的末尾位置
xlapp.Workbooks.Open(myfilename)
Dim i As Integer
For i = 1 To 5000
If xlapp.Cells(i, 1) = "" Then
number = i
Exit For
End If
Next i
xlapp.Quit
End If
End Sub
错误是:实时错误91,对象变量或with块变量未设置~ 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询