Upload
sachin-dhawad
View
219
Download
1
Embed Size (px)
Citation preview
4/12/2014 Working with Excel Files Using VB6 - VB 6 sample code - developer Fusion
http://www.developerfusion.com/code/5322/working-with-excel-files-using-vb6/ 1/1
Home Visual Basic 6 Code
Working with Excel Files Using VB6
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.ApplicationDim xlsheet As Excel.WorksheetDim 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.QuitEnd 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.QuitEnd 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 = NothingEnd Sub
You might also like...
Recommended by
© 1999-2014 Developer Fusion Ltd Managed hosting by Everycity
ContributeWhy not write for us? Or you couldsubmit an event or a user group inyour area. Alternatively just tell uswhat you think!
Web DevelopmentASP.NET QuickstartProgramming newsJava programmingASP.NET tutorialsC# programming
Developer JobsASP.NET JobsJava JobsDeveloper Jobs
Our toolsWe've got automatic conversiontools to convert C# to VB.NET,VB.NET to C#. Also you cancompress javascript and compresscss and generate sql connectionstrings.
Visual Basic 6 VBA
Tweet
By Adil Hussain Raza, published on 01 Feb 2006 | Filed in 11 Comments
Excel ViewerSocket Programming in C# - Part 2USB Complete: The Developer's Guide (Complete Guides series)A Chat Client/Server Program for C#
Join us Sign in India
“Owning a computer without programming is like having a kitchen and using only the microwave oven”- Charles Petzold
Tutorials Code Training User Groups Books Podcasts Forum JobsNewsVisual Basic 6
9Like