Link to home
Start Free TrialLog in
Avatar of raybetts
raybettsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB and Excel 2000

Hi

I need to write some code to essentially do the following:

Open an excel file in VB6

Traverse 2 sheets, taking data from specified cells and loading them into an excel object within vb6

As above, but write / format cells

Save the excel file.

Never really used Excel object model before and it seems a little tough to get to grips with.

Any url's highlighting examples of the above or snippets of code will be much appreciated.

Thanks,
Ray
Avatar of leonstryker
leonstryker
Flag of United States of America image

Esablish a reference to the Microsoft Excel object then:

Dim xl As Excel.Application
Dim wkbSource As Excel.Workbook
Dim wshSource As Excel.Worksheet
Dim rngSource As Excel.Range
 
Set xl = New Excel.Application
xl.Visible = True
Set wkbSource = wl.Workbooks.Open(strPath & strFile)
Set wshSource = wkbSource.Worksheets("Sheet1")
Set rngSource = wshSource.Range("A1")

' And so on
'Don't forget to close all objects the you are done.  If you need help with syntax, you can use the Macro recorder in Excel then copy the code into VB and modify it.

Leon


Avatar of raybetts

ASKER

Thanks leon, that helps a lot.

The only other thing I cannot figure out is this:

Last populated column
Last populated row

So that I can loop till last col and row and take the data into a db.

If you know this, then you have the points :-)
ASKER CERTIFIED SOLUTION
Avatar of leonstryker
leonstryker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the grade,

Leon