Is anyone aware of a good resource online for detailed information on the use of ole excel objects(embeded workbooks, worksheets, etc…) in VB6? I’m maintaining an application that makes heavy use of these conrols and I’m having a lot of trouble getting them to work properly for the user’s of this program. The scattered bits of Q&A I can find online related to ole excel controls is very limited and not very definitive. Obviously, I have read through what there is on MSDN but I’m not finding it very helpful so I would like to find another good source of reference.
I’m not sure this is helpful for embedding Excel, but assuming that the Excel engine is at the core of the embedded controls, you can look here for an alphabetized reference of the objects available for Excel 2003.
And here for the root of the Excel VBA reference, which includes a section “Concepts” that discusses the major objects, like workbooks and worksheets, cells and ranges, etc.
You’ll have to set a reference to the Excel objects in your project before you can create any of these objects. Under Project/References, you’ll find something like “Microsoft Excel 9.0 Object Library.” (I have Office 2000, thus the 9.0. Based on the links above, I imagine that for Excel 2003 you’ll see Excel 11.)
In your code, do something like this:
' Start a new workbook in Excel ' Dim oExcel As Excel.Application Dim oBook As Excel.Workbook ' Launch an instance of Microsoft Excel ' Set oExcel = new Excel.Application Set oBook = oExcel.Workbooks.Add
Then proceed to code against the application, workbooks, etc. The above code will create an instance of Excel that’s not embedded, but in it’s own window. One thing to be aware of is that by default, that Excel instance will not be visible. You have to set the Visible property to True before you can see it.
Hope this helps.
Any book on Excel VBA should help as you can copy and paste code from VBA to VB6. I would start there.
Also trying to do what you want to do in Excel with VBA then putting it into your VB6 project will also help. Then you’ll have access to all the VBA help in Excel (if you installed it.. it doesn’t always install by default).