how to export data to excel format from Visual basic

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bimalkumar
    New Member
    • Sep 2006
    • 7

    how to export data to excel format from Visual basic

    hi 2 all,
    i m using some txt boxes and few combo box in my form. how do i export the txt box and combobox data to excel sheet directly without using any database.just get the data from txt box and combo box and export it to excel.

    while answering pls remember i m not regular VB coder. I just do it for some small application.
    pls help me.
  • DPK
    New Member
    • Sep 2006
    • 16

    #2
    Dim appxl
    Dim Book As Excel.Workbooks
    Dim Wsheet As Excel.Worksheet
    'Dim RngWSheet As Excel.Range
    FileName = "c:\temp\new.xl s"
    Set appxl = CreateObject("E xcel.Applicatio n")
    Set Book = appxl.Workbooks
    Set Wsheet = Book.Add.Worksh eets(1)
    'Set rngWSheet = Wsheet.Cells
    appxl.Visible = True

    Wsheet.Cells(1, 1) = combo.Text/text1.text

    Wsheet.SaveAs (FileName)
    Book.Close

    Comment

    • bimalkumar
      New Member
      • Sep 2006
      • 7

      #3
      Thanks for ur rply.

      Originally posted by DPK
      Dim appxl
      Dim Book As Excel.Workbooks
      Dim Wsheet As Excel.Worksheet
      'Dim RngWSheet As Excel.Range
      FileName = "c:\temp\new.xl s"
      Set appxl = CreateObject("E xcel.Applicatio n")
      Set Book = appxl.Workbooks
      Set Wsheet = Book.Add.Worksh eets(1)
      'Set rngWSheet = Wsheet.Cells
      appxl.Visible = True

      Wsheet.Cells(1, 1) = combo.Text/text1.text

      Wsheet.SaveAs (FileName)
      Book.Close

      Comment

      • bimalkumar
        New Member
        • Sep 2006
        • 7

        #4
        Originally posted by bimalkumar
        Thanks for ur rply.
        hi,
        when i use your code it gives me error "user-defined type not defined". Is there any component to be used for this code.

        pls help me

        Comment

        • DPK
          New Member
          • Sep 2006
          • 16

          #5
          Originally posted by bimalkumar
          hi,
          when i use your code it gives me error "user-defined type not defined". Is there any component to be used for this code.

          pls help me

          Hi Vimal !

          U just have to give it reference of " Microsoft Excel Object Library "
          Just check this check Box From Menu -[ Project > reference ].

          Comment

          • dedydut
            New Member
            • Nov 2007
            • 1

            #6
            Originally posted by DPK
            Hi Vimal !

            U just have to give it reference of " Microsoft Excel Object Library "
            Just check this check Box From Menu -[ Project > reference ].
            Hi DPK, what if i want to add more data in excel... for example,
            i have export data from "Database A" in excel file "test.xls"
            now i want to export data from "Database B" in the same excel file, without replacing old data. and the result in excel file is "Database A" and "Database B" in one file... how to do that... thanks for your help...

            Comment

            Working...