Friday, 4 May 2012

0 Export to Excel in VB6/ Visual basic 6.0

Jaskumarblogspot.com

 Dim objexcel As Object


   Dim oBook As Object


   Dim oSheet As Object

   Set objexcel= CreateObject ' //Use To Create or open  Excel.Application//


   Set objbook = oExcel.Workbooks.Add


   Set oSheet = objbook.Worksheets(1)

   'Create the connection with database

   Dim sNWind As String    '// snwind is a string data type variable which is use to store path of database file

   sNWind = _
      "Path of your data base file (for example C:\data1.mdb)"

   Dim oQryTable As Object

   Set oQryTable = oSheet.QueryTables.Add( _
   "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
      sNWind & ";", oSheet.Range("A1"), "Select * from Table name")
   
  oQryTable.RefreshStyle = xlInsertEntireRows
  
   oQryTable.Refresh False


   'Save the Workbook and Quit Excel


   objbook.SaveAs "C:\empreport.xls"
   
   objexcel.Quit          '// closing the excel object


   MsgBox "report save at C:\empreport.xls"

0 comments:

Post a Comment

 

Coding Authority Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates