If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How to send an array of data to Excel using early binding?

I've been trying to write "early binding" code to control Excel with Automation. I've made considerable progress but can't figure out how to write a SAFEARRAY of numbers to Excel. Here is some simplified code:

This simplified code looks good except there is no SetValue function for pRange. In fact, pRange is very limited in the number of functions available. How do you send an array of data to Excel using early binding?

Re: How to send an array of data to Excel using early binding?

Thank you, Victor for your quick reply. You have sent me an excellent reference on how to send an array to Excel using late binding. If you can find a similar reference for early binding, I would be very happy. Note the reference here on the difference between early and late binding: https://support.microsoft.com/en-us/...-in-automation

The reason I want to do early binding is that I need to get better performance, which is one of the advantages of early binding. With early binding I have to specify the object with an import statement:

It writes "Value2" to the A1 cell. But unlike your reference, which shows how to send a SAFEARRAY "saRet" with the "range" function put_Value(covOptional,COleVariant(saRet)), neither pRange nor pd have a put_Value function. Unfortunately, the helper on MSDN quit responding to my queries.

I did notice that IRange has a put_Value function so I made an attempt with this code:

Re: How to send an array of data to Excel using early binding?

Actually, I figured out how to do it. In my March 25 email, when I showed the other helper's example, I misinterpreted the "Value2" as a string being sent. Actually, it was the name of a "put" function, put_Value2(). So it works to put a SAFEARRY in there, using "Value" or Value2". Here is the code:

Re: How to send an array of data to Excel using early binding?

Originally Posted by garyflet1

Actually, I figured out how to do it. In my March 25 email, when I showed the other helper's example, I misinterpreted the "Value2" as a string being sent. Actually, it was the name of a "put" function, put_Value2(). So it works to put a SAFEARRY in there, using "Value" or Value2". Here is the code:

Advertiser Disclosure:
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.