Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Late Binding issue with Excel.Application object [email protected][_2_] Excel Discussion (Misc queries) 2 August 4th 09 08:10 AM
Late binding to Excel from Access causing Object error EagleOne@microsoftdiscussiongroups[_2_] Excel Discussion (Misc queries) 4 June 14th 08 12:45 AM
Late Binding/Object Library Probelms bony_tony Excel Programming 1 July 27th 07 04:50 PM
VBA References - when is Office Object Library Reference set? Best practice re. Early/Late binding ... AndyB Excel Programming 5 April 22nd 04 02:11 PM
Creating a MailItem in Outlook from Excel using Late Binding Steven Kelder Excel Programming 3 December 17th 03 05:34 PM


All times are GMT +1. The time now is 10:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"