Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
late binding - creating worksheet object
So we've used a little useful Access app in-house for a while and are
now building it out for a client. I'm no VBA guru, and am struggling a bit with the late-binding conversions - seems I'm making things harder than they should be. 1. I have a the Excel Object Model reference, check; 2. Project takes a parameterized SQL query, instantiates a new Excel workbook, and pastes the contents into a worksheet; 3. And I think I'm Dimming the right Objects: ----------------------------------------- Dim xlAp As Object Dim xlWs As Object Set xlAp = CreateObject("Excel.Application") Set xlWs = CreateObject("Excel.Sheet") ----------------------------------------- Seems the Application object replaces the Workbook object in my Early Binding app, but I'm failing to open a new worksheet. Next: ----------------------------------------- xlApp.Visible = True ' welcome to my trouble: Set xlWs = xlApp.ActiveSheet ' <--- that sets xlWs to a null, I think since the worksheet still needs added... ' second attempt Set xlWs = xlApp.Sheets.Add(Type:="xlWorksheet") ' <--- that generates an 1004: "Application-defined or object-defined error" ----------------------------------------- From there I just step through my recordset pasting values, though I anticipate one more problem since Cells is not a method of Sheets (but of the Application object) ... do I just specify ActiveSheet here? ----------------------------------------- i = 1 For Each fld In rs.Fields xlApp.Cells(1, i).Value = fld.Name ' i = i + 1 Next fld ----------------------------------------- Thanks for setting my wrong-thinking right, Jeff |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
late binding - creating worksheet object
You'll need a workbook
Dim xlAp As Object Dim xlWb As Object Dim xlWs As Object Set xlAp = CreateObject("Excel.Application") xlAp.Visible = True Set xlWb = xlAp.Workbooks.Add Set xlWs = xlWb.Worksheets(1) -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Jeff Norville" wrote in message ... So we've used a little useful Access app in-house for a while and are now building it out for a client. I'm no VBA guru, and am struggling a bit with the late-binding conversions - seems I'm making things harder than they should be. 1. I have a the Excel Object Model reference, check; 2. Project takes a parameterized SQL query, instantiates a new Excel workbook, and pastes the contents into a worksheet; 3. And I think I'm Dimming the right Objects: ----------------------------------------- Dim xlAp As Object Dim xlWs As Object Set xlAp = CreateObject("Excel.Application") Set xlWs = CreateObject("Excel.Sheet") ----------------------------------------- Seems the Application object replaces the Workbook object in my Early Binding app, but I'm failing to open a new worksheet. Next: ----------------------------------------- xlApp.Visible = True ' welcome to my trouble: Set xlWs = xlApp.ActiveSheet ' <--- that sets xlWs to a null, I think since the worksheet still needs added... ' second attempt Set xlWs = xlApp.Sheets.Add(Type:="xlWorksheet") ' <--- that generates an 1004: "Application-defined or object-defined error" ----------------------------------------- From there I just step through my recordset pasting values, though I anticipate one more problem since Cells is not a method of Sheets (but of the Application object) ... do I just specify ActiveSheet here? ----------------------------------------- i = 1 For Each fld In rs.Fields xlApp.Cells(1, i).Value = fld.Name ' i = i + 1 Next fld ----------------------------------------- Thanks for setting my wrong-thinking right, Jeff |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Late Binding issue with Excel.Application object | Excel Discussion (Misc queries) | |||
Late binding to Excel from Access causing Object error | Excel Discussion (Misc queries) | |||
Late Binding/Object Library Probelms | Excel Programming | |||
VBA References - when is Office Object Library Reference set? Best practice re. Early/Late binding ... | Excel Programming | |||
Creating a MailItem in Outlook from Excel using Late Binding | Excel Programming |