473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to automate Excel with Late Binding?

So I've decided to convert from Early Binding to Late Binding. Now that
I've been baptized, I need some instruction in the faith.

My former ways were thus:

Dim xlapp As Excel.Application
Set xlapp = CreateObject("Excel.Application")

and then I went off in debauchery like this:

lr = xlapp.Workbooks(strXlsFile).Worksheets(sn).Range(" A1").SpecialCells _
(xlCellTypeLastCell).Row
lc = xlapp.Workbooks(strXlsFile).Worksheets(sn).Range(" A1").SpecialCells _
(xlCellTypeLastCell).Column

Now that I've seen the light, I've amended my ways thusly:

Dim xlapp As Object
Set xlapp = CreateObject("Excel.Application")
(and removed the sinful reference to Microsoft Excel 11.0 Object Library)

But now, the code I so enjoyed above no longer works. I get a complie error
on xlCellTypeLastCell - "Variable not defined"

How do I use Excel automation with Late Binding?

Thanks in advance.
Nov 13 '05 #1
3 6702
The problem is that xlCellTypeLastCell is a constant defined in the Excel
library that you are no longer referencing. Unfortunately, you just have to
redefine the constant in your own application. To find out what the value of
the constant needs to be, go into an Excel project, open the object browser.

By the way, be careful to define your constants using the same type. There
are a few oddball cases in MS Office where if you pass, say, 2 as an Integer,
you get a type mismatch error, but if you pass 2 as a Long it works.

On Sat, 18 Jun 2005 02:07:54 GMT, "deko" <de**@deko.com> wrote:
So I've decided to convert from Early Binding to Late Binding. Now that
I've been baptized, I need some instruction in the faith.

My former ways were thus:

Dim xlapp As Excel.Application
Set xlapp = CreateObject("Excel.Application")

and then I went off in debauchery like this:

lr = xlapp.Workbooks(strXlsFile).Worksheets(sn).Range(" A1").SpecialCells _
(xlCellTypeLastCell).Row
lc = xlapp.Workbooks(strXlsFile).Worksheets(sn).Range(" A1").SpecialCells _
(xlCellTypeLastCell).Column

Now that I've seen the light, I've amended my ways thusly:

Dim xlapp As Object
Set xlapp = CreateObject("Excel.Application")
(and removed the sinful reference to Microsoft Excel 11.0 Object Library)

But now, the code I so enjoyed above no longer works. I get a complie error
on xlCellTypeLastCell - "Variable not defined"

How do I use Excel automation with Late Binding?

Thanks in advance.


Nov 13 '05 #2
> The problem is that xlCellTypeLastCell is a constant defined in the Excel
library that you are no longer referencing. Unfortunately, you just have to redefine the constant in your own application. To find out what the value of the constant needs to be, go into an Excel project, open the object browser.
By the way, be careful to define your constants using the same type. There are a few oddball cases in MS Office where if you pass, say, 2 as an Integer, you get a type mismatch error, but if you pass 2 as a Long it works.


I see.

So I tried this:

'Excel Constants ============================
Private Const xlCellTypeLastCell As Long = 11
Private Const xlCenter As Long = -4108
Private Const xlColumns As Long = 2
Private Const xlLineMarkers As Long = 65
Private Const xlCategory As Long = 1
Private Const xlPrimary As Long = 1
Private Const xlValue As Long = 2
Private Const xlThin As Long = 2
Private Const xlContinuous As Long = 1
Private Const xlDiamond As Long = 2
Private Const xlY As Long = 1
Private Const xlBoth As Long = 1
Private Const xlCustom As Long = -4114
Private Const xlNone As Long = -4142
Private Const xlDot As Long = -4118
Private Const xlCategoryScale As Long = 2
Private Const xlMedium As Long = -4138
Private Const xlAutomatic As Long = -4105
'===========================================
(since I have more than one function that uses these constants)
(by the way - do they all need to be Longs? - the Excel Object Browser did
not specify a data type)

In my first function I have this:

Dim xlapp as Object
Set xlapp = CreateObject("Excel.Application")

And then I pass xlapp to another Function like this:

Private Function CreateBBcharts(blnSummary As Boolean, _
frm As Form, sn As String, strStop As String, strTitle As String, _
strXlsFile As String, xlapp As Object) As Boolean

Formerly I did this:

Private Function CreateBBcharts(blnSummary As Boolean, _
frm As Form, sn As String, strStop As String, strTitle As String, _
strXlsFile As String, xlapp As Excel.Application) As Boolean

Seems to be working...

Anything else I should know about Late Binding in this context?

Thanks for your help!!


Nov 13 '05 #3
On Sat, 18 Jun 2005 02:49:11 GMT, "deko" <de**@deko.com> wrote:
The problem is that xlCellTypeLastCell is a constant defined in the Excel
library that you are no longer referencing. Unfortunately, you just have

to
redefine the constant in your own application. To find out what the value

of
the constant needs to be, go into an Excel project, open the object

browser.

By the way, be careful to define your constants using the same type.

There
are a few oddball cases in MS Office where if you pass, say, 2 as an

Integer,
you get a type mismatch error, but if you pass 2 as a Long it works.


I see.

So I tried this:

'Excel Constants ============================
Private Const xlCellTypeLastCell As Long = 11
Private Const xlCenter As Long = -4108
Private Const xlColumns As Long = 2
Private Const xlLineMarkers As Long = 65
Private Const xlCategory As Long = 1
Private Const xlPrimary As Long = 1
Private Const xlValue As Long = 2
Private Const xlThin As Long = 2
Private Const xlContinuous As Long = 1
Private Const xlDiamond As Long = 2
Private Const xlY As Long = 1
Private Const xlBoth As Long = 1
Private Const xlCustom As Long = -4114
Private Const xlNone As Long = -4142
Private Const xlDot As Long = -4118
Private Const xlCategoryScale As Long = 2
Private Const xlMedium As Long = -4138
Private Const xlAutomatic As Long = -4105
'===========================================
(since I have more than one function that uses these constants)
(by the way - do they all need to be Longs? - the Excel Object Browser did
not specify a data type)

In my first function I have this:

Dim xlapp as Object
Set xlapp = CreateObject("Excel.Application")

And then I pass xlapp to another Function like this:

Private Function CreateBBcharts(blnSummary As Boolean, _
frm As Form, sn As String, strStop As String, strTitle As String, _
strXlsFile As String, xlapp As Object) As Boolean

Formerly I did this:

Private Function CreateBBcharts(blnSummary As Boolean, _
frm As Form, sn As String, strStop As String, strTitle As String, _
strXlsFile As String, xlapp As Excel.Application) As Boolean

Seems to be working...

Anything else I should know about Late Binding in this context?


Not that I can think of. You should be good to go. If you do Excel calls
from other modules, you'll ahve to make those constants Public is all.
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WZ | last post by:
I used the following code to create a workbook and save it in a webapplication. dim oExcel As Excel.ApplicationClass dim oBook As Excel.WorkbookClass dim obooks As Excel.Workbooks dim designb...
8
by: deko | last post by:
When using automation (and especially with early binding) I've heard it is best to use explicit references to everything. For example: Dim xlChart as Excel.Chart rather than Dim objChart...
3
by: Dent2 | last post by:
I wrote a nice C# excel routine to automate the formatting of some raw CSV data. I wrote the routine on a WinXP computer with Visual Studio .NET 2003 and Office XP installed. It compiled and ran...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
11
by: BrianDH | last post by:
Hi Is there a way, in VB.Net, to write a windows based program that will use more than one version of Office (Excel)? Example: if office 2000 then else if office 2003 then. Is this possible? ...
0
by: jim4u | last post by:
Hi gurus, I have an automation add-in created using C# for Excel, in which I am exposing a number of functions. Is there any way I can add help-text the way excel does for other categories like...
1
by: J Daniel Melton | last post by:
Hello, I am using late binding in a managed VC++ .NET 2003 application. I used KB 302902 (for C#) as a starting point and converted it to managed C++. I built a managed class that is intantiated...
2
by: kogrover | last post by:
ISSUE: COM Excel Sort works with Early Binding, but not Late Binding, but py2exe only does Late Binding I have code similar to this (type from notes, so there may be a typo...) import...
2
by: GS | last post by:
I have installed the ms PIA for ofc XP, and followed the article http://support.microsoft.com/kb/247412/ trying to paste into a worksheet However I got late binding not allowed errors .......
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.