[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB and Excel 2000

Posted on 2005-04-28
4
Medium Priority
?
201 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:raybetts
  • 3
4 Comments
 
LVL 29

Expert Comment

by:leonstryker
ID: 13885993
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


0
 
LVL 1

Author Comment

by:raybetts
ID: 13886756
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 :-)
0
 
LVL 29

Accepted Solution

by:
leonstryker earned 500 total points
ID: 13886825
That you need to do is find the last cell on the sheet:

Dim rngLastCell As Excel.Range, intLastRow As integer, intLastCol As Integer

Set rngLastCell = wshSource.Cells.SpecialCells(xlCellTypeLastCell)

intLastRow = rngLastCell.Row
intLastCol = rngLastCell.Column

Leon
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 13886868
Thanks for the grade,

Leon
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question