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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding columns to an excel sheet from vb6 1

Status
Not open for further replies.

pedro404

Programmer
Feb 17, 2004
11
DE
hi
can anyone help?
i need to know how to open an existing excel worksheet within a vb6 application and add to the existing records. ie A1-D7 already there, need to add from E1 to H7.
thanks in advance.
pedro404
 
You need to add Microsoft Excel x.x Objects to the project references.

Then it depends a little on how many sheets, which one etc. but basically

Dim xApp As New Excel.Application

xApp.Workbooks.Open ("C:\filename")

xApp.ActiveSheet.Cells(1, 5).Value = "E1"
xApp.ActiveSheet.Cells(1, 6).Value = "F1"
xApp.ActiveSheet.Cells(1, 7).Value = "G1"
xApp.ActiveSheet.Cells(1, 8).Value = "H1"

xApp.ActiveWorkbook.Save
xApp.ActiveWorkbook.Close

Set xApp = Nothing

Would set the first row E-H to those values. The cell coordinates could be variables in a loop etc.

 
cheers rdroske
that worked a treat, thanks a lot

pedro404
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top