396,352 Members | 3,910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 396,352 IT Pros & Developers. It's quick & easy.

how to export data to excel format from Visual basic

bimalkumar
P: 7
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.
Sep 19 '06 #1
Share this Question
Share on Google+
5 Replies


DPK
P: 16
DPK
Dim appxl
Dim Book As Excel.Workbooks
Dim Wsheet As Excel.Worksheet
'Dim RngWSheet As Excel.Range
FileName = "c:\temp\new.xls"
Set appxl = CreateObject("Excel.Application")
Set Book = appxl.Workbooks
Set Wsheet = Book.Add.Worksheets(1)
'Set rngWSheet = Wsheet.Cells
appxl.Visible = True

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

Wsheet.SaveAs (FileName)
Book.Close
Sep 20 '06 #2

bimalkumar
P: 7
Thanks for ur rply.

Dim appxl
Dim Book As Excel.Workbooks
Dim Wsheet As Excel.Worksheet
'Dim RngWSheet As Excel.Range
FileName = "c:\temp\new.xls"
Set appxl = CreateObject("Excel.Application")
Set Book = appxl.Workbooks
Set Wsheet = Book.Add.Worksheets(1)
'Set rngWSheet = Wsheet.Cells
appxl.Visible = True

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

Wsheet.SaveAs (FileName)
Book.Close
Sep 20 '06 #3

bimalkumar
P: 7
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
Sep 20 '06 #4

DPK
P: 16
DPK
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 ].
Sep 22 '06 #5

dedydut
P: 1
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...
Nov 16 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.