473,387 Members | 3,781 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,387 software developers and data experts.

excel interop - how to avoid late binding?

GS
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
....
webOCWraooer,Copy // get the desired data into clapboard

'Create a new workbook in Excel
Dim oExcel As Object
Dim oBook As Object
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add ' < option strict on disallows late
binding>
'Paste the data
oBook.Worksheets(1).Range("A1").Select ' < option strict on disallows
late binding>

oBook.Worksheets(1).Paste ' < option strict on disallows late binding>

so I tried

....
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
oExcel = New Excel.Application
oBook = oExcel.Workbooks.Add ' so far so good
'Paste the data
oBook.Worksheets(1).Range("A1").Select() ' oops late binding
error
oBook.Worksheets(1).Paste() ' same as above

How do get around the last two?

I tried
oSheet As Excel.Worksheets
Dim oRange As Excel.Range

oSheet = oBook.ActiveSheets(1)
but that did not help
please Help


Jun 16 '07 #1
2 8308
GS
Now I have cut down the errors to one:
Dim oSheet As Excel.Worksheet
Dim oRange As Excel.Range

oSheet = oExcel.ActiveWorkbook.ActiveSheet() ' < still
implicit conv form obj to microsoft.office.interop.excel.worksheet
' also tried oExcel.ActiveSheet
' do not work: oBook.Worksheets(1) 'oBook.Sheets

"GS" <gs**********************@msnews.Nomail.comwrote in message
news:Oy**************@TK2MSFTNGP06.phx.gbl...
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
...
webOCWraooer,Copy // get the desired data into clapboard

'Create a new workbook in Excel
Dim oExcel As Object
Dim oBook As Object
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add ' < option strict on disallows late
binding>
'Paste the data
oBook.Worksheets(1).Range("A1").Select ' < option strict on disallows
late binding>

oBook.Worksheets(1).Paste ' < option strict on disallows late
binding>
>
so I tried

...
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
oExcel = New Excel.Application
oBook = oExcel.Workbooks.Add ' so far so good
'Paste the data
oBook.Worksheets(1).Range("A1").Select() ' oops late binding
error
oBook.Worksheets(1).Paste() ' same as above

How do get around the last two?

I tried
oSheet As Excel.Worksheets
Dim oRange As Excel.Range

oSheet = oBook.ActiveSheets(1)
but that did not help
please Help


Jun 16 '07 #2
GS
I think I got the answer by a twisted way.
I was stuck in vb, I went to C# got something the syntactically correct, get
the code fragment translated back to vb using online converter and here is
something VB will accept:

import Microsoft.Office.Interop

'Create a new workbook in Excel

'Create a new workbook in Excel
Dim oExcel As Microsoft.Office.Interop.Excel.Application
Dim oBook As Microsoft.Office.Interop.Excel.Workbook
oExcel = New Microsoft.Office.Interop.Excel.Application()
oBook = New Microsoft.Office.Interop.Excel.Workbook()

'Paste the data

Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim oRange As Microsoft.Office.Interop.Excel.Range
oSheet = DirectCast(oBook.ActiveSheet,
Microsoft.Office.Interop.Excel.Worksheet)
' aha, the trick is to use directcast

oRange = oSheet.Range("A1")
oSheet.Paste()
Jun 16 '07 #3

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

Similar topics

5
by: William Ryan | last post by:
In a nutshell, I need to get the name of the object that was just pressed (in this case, the object will be a radioButton). I want to write one handler for all four radio buttons and branch off...
3
by: deko | last post by:
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...
3
by: Thomas Müller-Lynch | last post by:
How can I avoid late binding with the directive strict = tru My ASP .net-file looks like this <%@DEBUG=true TRACE=true Strict=false EXPLICIT=true% .. dim footerValues as Arra footerValues =...
3
by: Lenonardo | last post by:
Can anyone tell me how I refer to Excel constants when using late binding. I've tried searching the Excel.application interface but can't find any reference in the hierarchy to an object that...
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
6
by: active | last post by:
Me is a combobox and the items are objects with a property "String1" The problem with the following construct is that one does not know if there is a typo until run time. ...
6
by: Stephany Young | last post by:
Using VS2005 and VB.NET and given a Windows Forms application with a single form (Form1) with 2 buttons (Button1 and Button2), I am attempting to instantiate an instance of Excel utilising late...
4
by: =?Utf-8?B?Y2xhcmE=?= | last post by:
Hi all, what is the difference between the late binding and reflection? clara -- thank you so much for your help
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.