这里我有我的vb6代码,可以使用excel文件。 (我把这个代码从其他网站上删除。)这段代码编译和构建,但是当我点击f5时,表单不会形成。如果我删除了Class中的所有代码,则会弹出。
我该如何解决这个问题? 对不起,我是vb6的新手,但不是一般的编码。
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim xl As New Excel.Application
Dim xlsheet As Excel.Worksheet
Dim xlwbook As Excel.Workbook
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'the benifit of placing numbers in (row, col) is that you
'can loop through different directions if required. I could
'have used column names like "A1" 'etc.
'Text1.Text = xlsheet.Cells(2, 1) ' row 2 col 1
'Text2.Text = xlsheet.Cells(2, 2) ' row 2 col 2
'don't forget to do this or you'll not be able to open
'book1.xls again, untill you restart you pc.
xl.ActiveWorkbook.Close(False, "f:\a.xls")
xl.Quit()
End Sub
Private Sub Form_Load()
xlwbook = xl.Workbooks.Open("f:\a.xls")
xlsheet = xlwbook.Sheets.Item(1)
End Sub
Private Sub Form_Unload(Cancel As Integer)
xlwbook = Nothing
xl = Nothing
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
xlsheet.Cells(2, 1) = "adsfasdfasdf"
xlsheet.Cells(2, 2) = "qwerqwer"
xlwbook.Save()
'don't forget to do this or you'll not be able to open
'book1.xls again, untill you restart you pc.
xl.ActiveWorkbook.Close(False, "f:\a.xls")
xl.Quit()
End Sub
End Class
答案 0 :(得分:2)
然后,这意味着您没有添加对项目的引用
点击代码链接和更多详情..
http://vb.net-informations.com/excel-2007/vb.net_excel_2007_open_file.htm
答案 1 :(得分:0)
仔细检查文件名,路径和扩展名。
("f:\a.xls")
扩展名可能是xlsx。
同时检查表1的名称。