Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data from a form into Excel 1

Status
Not open for further replies.

LyndonLudlow

Programmer
Jul 11, 2001
1
CA
I was just wondering if someone could tell me how to get data from a form in VB into an Excel Spreadsheet. I know how to put data into a database from VB, and just wondering is it similar?
 
The method I have used in the past goes somthing like this. First you have to reference the Microsoft Excel object in your project (I have v 8 on my machine). Next you have to declare your objects:

Dim xlApp as Excel.Application
Dim xlBook as Excel.Workbook
Dim xlSheet as Excel.Worksheet
Dim xlButton as Excel.Button

Set xlApp = Excel.Application
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets.Add
Set xlButton = xlSheet.Buttons.Add(300, 33, 100, 15)

'Now you have access to xlButton.OnAction, xlButton.Caption
'if you want to assign macros to the button.

With xlSheet
.Cells(x,y).Value = "Hello"
End With


You can access all the objects in Excel such as Range, Selection...


Hope this helps. Colin Chevrier
Colin_Chevrier@dmr.ca

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top