Save Data into Excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • susisri
    New Member
    • May 2007
    • 1

    #1

    Save Data into Excel

    Hi,
    if any one please clear my doubt.
    i created one form in vb.it contains(empid, othertsk,descrp tion....etc)
    if any user fill these details click ok then these details are saved into the Excel file.
    can anyone tell how to write the code for above form?
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by susisri
    Hi,
    if any one please clear my doubt.
    i created one form in vb.it contains(empid, othertsk,descrp tion....etc)
    if any user fill these details click ok then these details are saved into the Excel file.
    can anyone tell how to write the code for above form?
    Hey there, susisri!

    Here is a very simple connection to Excel, you'll need to do some leg work to do what you need though:

    Code:
    'Declare variables here and be sure to add a [B]reference[/B]
    Go to Project/References and Check [B]Microsoft Excel 9.0 Object library[/B].
    Dim xl As New Excel.Application
    Dim xlsheet As Excel.Worksheet
    Dim xlWBook As Excel.Workbook
    'Don't forget to Quit or you'll have restart your machine/program.
    Private Sub Load2Excel_Click() 'Your button
        xlsheet.Cells(1, 1) = Text1.Text
        xlsheet.Cells(1, 2) = Text2.Text
       xlWBook.Save
        xl.ActiveWorkbook.Close False, "C:\Excel_Me.xls"
        xl.Quit
    End Sub
    
    Private Sub Form_Load()
        Set xlWBook = xl.Workbooks.Open("C:\Excel_Me.xls")
        Set xlsheet = xlWBook.Sheets.Item(1)
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        Set xlWBook = Nothing
        Set xl = Nothing
    End Sub
    Good luck and welcome!

    Comment

    • wassup
      New Member
      • May 2007
      • 34

      #3
      Originally posted by susisri
      Hi,
      if any one please clear my doubt.
      i created one form in vb.it contains(empid, othertsk,descrp tion....etc)
      if any user fill these details click ok then these details are saved into the Excel file.
      can anyone tell how to write the code for above form?
      Hi susisri,
      you can try to read this thread.
      http://www.thescripts. com/forum/thread645157.ht ml
      it may help you a lot.

      Comment

      Working...