Search
Enter Keywords:
Home
Visual Basic 6 (VB6) Code to Put Data in an Excel Spreadsheet PDF Print E-mail
User Rating: / 2
PoorBest 
Written by Michael Salsbury   
Wednesday, 15 June 2005

The following Visual Basic 6.0 (VB6) subroutine will show you how to write data into Microsoft Excel spreadsheet cells from your program.

As with all my sample code, it's provided as-is without warranty or support.  Use at your own risk.

Private Sub LoadExcel()
   ' Create the objects needed

   Dim excelApp As Object
   Dim excelWorkbook As Object
   Dim excelSheet As Object
   '
   ' Create an instance of Microsoft Excel
   '
   Set excelApp = CreateObject("Excel.application")
   '
   ' Make Excel visible to the user.
   '
   excelApp.Visible = True
   '
   ' Add a new Workbook to Excel
   '
   Set excelWorkbook = excelApp.workbooks.Add
   '
   ' Select the worksheet
   '

   Set excelSheet = excelWorkbook.worksheets(1)
   '
   ' Fill in some values
   '

   excelSheet.range("A1:A5").numberformat = "@"
   excelSheet.range("A1").Value = "@"
   excelSheet.range("A2").Value = "mar25"
   excelSheet.range("A3").Value = "sep21"
   excelSheet.range("A4").Value = "abc12"
   excelSheet.range("A5").Value = "xxx99"
   excelSheet.range("B1:A4").numberformat = "General"
   excelSheet.range("B1").Value = "General"
   excelSheet.range("B2").Value = "mar25"
   excelSheet.range("B3").Value = "sep21"
   excelSheet.range("B4").Value = "abc12"
   excelSheet.range("B5").Value = "xxx99"
   '
   ' Save the workbook as c:\test.xls
   '
   excelWorkbook.saveas ("c:\test.xls")
   '
   ' Close the workbook and quit Excel
   '
   excelWorkbook.Close
   excelApp.quit
   '
   ' Get rid of the objects we've created.
   '
   Set excelSheet = Nothing
   Set excelWorkbook = Nothing
   Set excelApp = Nothing
     
End Sub


The following text is not intended for the human readers of this page, but rather for electronic readers who are looking for lots of specific words to be here to define and categorize this page:

This page contains a sample subroutine written in Microsoft Visual Basic 6.0 to place some sample data into an Excel spreadsheet.  It shows how using certain techniques to place that data into a spreadsheet will result in garbled data being stored by Excel, as Excel tries to "understand" the data you're inputting.  It also shows an alternate input method that essentially tells Excel that it shouldn't try to interpret the input.  Sample VB or VB6 code to put data into Excel.  Example source code to place data in Excel from VB6 or rather Visual Basic 6.0.  Yes, this sample subroutine shows code that will allow your Visual Basic (VB) program to put some data into Microsoft Excel spreadsheets.  Again, for those non-human readers, free code to input data into an Excel spreadsheet from VB6 (Microsoft Visual Basic 6.0).


Related Blogs:

Related Links:

Last Updated ( Friday, 24 March 2006 )
< Previous   Next >

Main Menu
Home
Blog
Photos
Links
Search
Site Index
Feedback
Administrator
Featured Links
BlogInspiration
SpamToons
Shawn Prince's Blog
Jack Ludwig's Blog
Mike Cramer's Site
Fark
Slashdot
Woot!
Cigar Envy
John Kricfalusi's Blog
CigarBlog 101
Cigars 101 Forum
Sponsored Links


View Site Stats