The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

Visual Basic / Excel Help request by origin_importe2008-01-17 18:44:39
  If he's using the VB environment within Excel, by hadji2008-01-17 18:52:44
    If he's trying to do that, then the interface is by bwkaz 2008-01-17 19:12:19
similar, he just needs a separate environment that has COM support.

VB6, for instance, has a GetObject function that will take the path to an xls file (at least under office <=2003) as one of its arguments, and return the Excel.Workbook object that the xls file contains. It's also possible to just ShellExecute the xls file, and then look in the COM running-object-table for a moniker whose string value is some Excel-related GUID (not sure where the GUID comes from, just that it exists) -- this is an Excel.Application, which has a Workbooks collection, which contains each open workbook. I'd use that option from non-VB6 languages.

But assuming VB6, either this:

Set wb = GetObject("\path\to\file.xls", "Excel.Workbook")

or this:

Shell "\path\to\file.xls"
<pause -- it takes a while for Excel to register itself in the ROT, and you might need to give it focus too>
Set wb = GetObject(, "Excel.Application").Workbooks(0)

should set wb to the Excel.Workbook in question. (The latter might need some explaining: When you don't give GetObject a first argument, it generates a GUID from the ProgID given in the second argument, and looks in the running object table for a moniker containing that GUID. You'll probably have to do that lookup yourself from other languages, or use a combination of IRunningObjectTable's enumeration functions and QueryInterface. Look for an object that supports Excel's Application interface; I'm not sure what the IID is.)

Anyway, once you have that, you should be able to do these:

MsgBox wb.Worksheets(0).Cells(row, column).Value
wb.Worksheets(0).Cells(row, column).Value = "blahblah"

(In VB6, setting a reference to the Excel typelib (excel.olb, I think) will give you IntelliSense, which will show lots of other properties on the workbook and worksheet.)

Note that you'll have to explicitly tell Excel to exit, as well: if you don't, then I think you'll leave an excel.exe process hanging around. To do that, call the Quit method on the Application interface, obtained from the workbook object (wb.Application.Quit() or similar). You could also leave a reference to the Application around if you used the second GetObject above, but this'll work regardless. :-)
[ Reply ]

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)