Solved

Excel   _Application.Run with array as parameter

Posted on 2000-05-15
1
296 Views
Last Modified: 2013-11-20
In vb the call looks like this

ExcelApp---Excel.Application

dim MyArray(2)as double
MyArray(1)=1
MyArray(2)=2
ExcelApp.Run("SomeFunc",MyArray)
Works well

How can I do that in MFC
My code is like:
_______________________________________
COleVariant FuncName;FuncName.bstrVal= SysAllocString(L"SomeFunc");
COleVariant MyArray;
double tmp[2]={1,2};
PutValues(&MyArray,tmp,2);
m_ExcelApp.Run(FuncName,MyArray);


The put values function is:
_______________________________________
void PutValues(COleVariant  *ThisArray, double *Arr, long nCount)
{
      int i = 0;      
      long *palDims = 0;
      double      rValue = 0.0;
      SAFEARRAY *psaData = 0;
      SAFEARRAYBOUND *pabound = 0;
      HRESULT      hRes = 0;      

      VariantInit( ThisArray );
        pabound = (SAFEARRAYBOUND *) malloc( 2 * sizeof(SAFEARRAYBOUND) );
      palDims = (long *) malloc( 2 * sizeof(long) );
      if( pabound && palDims )
            {
            pabound[0].cElements = nCount;
            pabound[0].lLbound = 0L;
            pabound[1].cElements = 1;
            pabound[1].lLbound = 0L;
            psaData = SafeArrayCreate( VT_R8, 2, pabound );
            for( i = 0; ( i < nCount) && ( hRes == S_OK) ; i++ )
            {
                palDims[0] = i;
              palDims[1] = 0;
              hRes = SafeArrayPutElement( psaData, palDims,&Arr[i]);
            }
             ThisArray->parray = psaData;
                ThisArray ->vt = VT_R8;
            ThisArray->vt|= VT_ARRAY;
            }
            free( pabound );
            free( palDims );
}


0
Comment
Question by:mdanny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 23

Accepted Solution

by:
naveenkohli earned 50 total points
ID: 2815250
Look at this Microsoft knowledge base article.

Article ID: Q186122
 

HOWTO: Use MFC to Automate Excel & Obtain an Array from a Range

http://support.microsoft.com/support/kb/articles/q186/1/22.asp

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question