Loading
Share Your Source Code or Article
Do you have source code, articles, tutorials, web links, and books to share? You can write your own content here. You can even have your own blog.
Submit now...
Submit now...
Sponsor
Receive Free Updates
Today's popular content
- How to Connect to a Database and Add/Update/Delete Record (55)
- Hotel Reservation System in MS Access (47)
- Free Hotel Management System Manual (39)
- Automated Voting System (38)
- My VB Program (37)
- Visual Basic .NET 2008 Tutorial (36)
- Payroll System (33)
- Hotel Reservation System (31)
- Hotel Reservation System (VB.NET) (30)
- A Simple Add, Edit, Delete, and Search using VB and MSAccess (30)
- 1 of 204
- ››
Random Post
- Object Oriented Compution Using Function (3,102)
- Order Billing Inventory System (5,051)
- Tiny audio player by Sparsh (1,241)
- Visual Basic Video Tutorial (5,055)
- Human Resource Management System (6,166)
- How to Rename SQL Server Database and the Database Filename (.mdf file) (1,956)
- Small Business SEO (1,900)
- Sending and Receiving SMS using AT Commands in .NET (6,336)
- New way to impress/propose your girl/boy friends (1,662)
- File Transfer - FTP Client/FTP Server (9,478)
- 1 of 133
- ››
The code is totally self explanatory, In the load event we're going to open the new instance of the excel library and our excel file “book1.xls” will be accessible from our code. Then we'll use Command1 to retrieve data from book1, please note that you must have some data in the excel file. Similarly Command2 is used to put/replace the data in the excel sheet cells.
'do declare these variables you need to add a reference
'to the microsoft excel 'xx' object library.
'you need two text boxes and two command buttons
'on the form, an excel file in c:\book1.xls
Dim xl As New Excel.Application
Dim xlsheet As Excel.Worksheet
Dim xlwbook As Excel.Workbook
Private Sub Command1_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, "c:\book1.xls"
xl.Quit
End Sub
Private Sub Command2_Click()
xlsheet.Cells(2, 1) = Text1.Text
xlsheet.Cells(2, 2) = Text2.Text
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, "c:\book1.xls"
xl.Quit
End Sub
Private Sub Form_Load()
Set xlwbook = xl.Workbooks.Open("c:\book1.xls")
Set xlsheet = xlwbook.Sheets.Item(1)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set xlwbook = Nothing
Set xl = Nothing
End Sub