ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel4 Call to get Function String (https://www.excelbanter.com/excel-programming/277574-re-excel4-call-get-function-string.html)

Rob Bovey

Excel4 Call to get Function String
 
"Matthew Wieder" wrote in message
...
How would I write the C++ XLL call that would take an XLOPER (of a
function) and get the string in that cell (i.e. the "=ThisFunc($A$3,
$F$7)") not the value that is returned by that function that is
displayed in the cell.


Hi Matthew,

I'm not sure I follow what you're asking for. Do you mean that if you
have the following function defined in your XLL:

EXPORT XLOPER MyFunc(XLOPER arg);

That you want a char* that looks something like "=MyFunc(A1)"?

That would seem to be self-evident. You know you have an equals sign
followed by the function name and a set of parenthesis containing a
comma-delimited list of the range addresses of the XLOPER arguments.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *




Matthew Wieder

Excel4 Call to get Function String
 
That is what I need, but I need the actual string, not aa version I can
reconstruct. The difference is that I need to know whether a single
cell was entered as "$B$1" or as "B1:B1" which are equivalent once the
become passed in as XLOPERS so I need to get the actual string from the
cell.
thanks!

Rob Bovey wrote:

"Matthew Wieder" wrote in message
...

How would I write the C++ XLL call that would take an XLOPER (of a
function) and get the string in that cell (i.e. the "=ThisFunc($A$3,
$F$7)") not the value that is returned by that function that is
displayed in the cell.



Hi Matthew,

I'm not sure I follow what you're asking for. Do you mean that if you
have the following function defined in your XLL:

EXPORT XLOPER MyFunc(XLOPER arg);

That you want a char* that looks something like "=MyFunc(A1)"?

That would seem to be self-evident. You know you have an equals sign
followed by the function name and a set of parenthesis containing a
comma-delimited list of the range addresses of the XLOPER arguments.



Rob Bovey

Excel4 Call to get Function String
 
"Matthew Wieder" wrote in message
...
That is what I need, but I need the actual string, not aa version I can
reconstruct. The difference is that I need to know whether a single
cell was entered as "$B$1" or as "B1:B1" which are equivalent once the
become passed in as XLOPERS so I need to get the actual string from the
cell.


Hi Matthew,

I've never tried to do this, so I don't know for sure that there's a
solution. The following seems like it ought to work:

XLOPER xlRef, xlFormula;
Excel4(xlfCaller, &xlRef, 0);
Excel4(xlfGetFormula, &xlFormula, 1, &xlRef);

but in the quick tests I've done it doesn't. I'll play with it some more
when I get back home tonight. and post again if I can get it working.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *



Matthew Wieder

Excel4 Call to get Function String
 
Yeah - I somehow combed ine net and discovered that same code segmant
which should do what I want, but the call to xlfGetFormula is failing
with a return code of 2 or "An invalid function number was supplied. If
you are using constants from XLCALL.H, this shouldn't happen." I checked
XLCall.h and xlfGetFormula is correctly defined as 106. I hope we can
solve this issue as it has become somewhat urgent for us.
thanks!

Rob Bovey wrote:

"Matthew Wieder" wrote in message
...

That is what I need, but I need the actual string, not aa version I can
reconstruct. The difference is that I need to know whether a single
cell was entered as "$B$1" or as "B1:B1" which are equivalent once the
become passed in as XLOPERS so I need to get the actual string from the
cell.



Hi Matthew,

I've never tried to do this, so I don't know for sure that there's a
solution. The following seems like it ought to work:

XLOPER xlRef, xlFormula;
Excel4(xlfCaller, &xlRef, 0);
Excel4(xlfGetFormula, &xlFormula, 1, &xlRef);

but in the quick tests I've done it doesn't. I'll play with it some more
when I get back home tonight. and post again if I can get it working.



Peter Huang [MSFT]

Excel4 Call to get Function String
 
Hi Matthew,

e.g. You have a MyFunc in xll and at A1 you using the formula
"=MyFunc(parameters)"
Then you need to call the Excel4 after the MyFunc return.
Here is my code.
XLOPER xlRef, xlFormula;
xlRef.xltype=xltypeSRef;
xlRef.val.sref.count =1;
xlRef.val.sref.ref.rwFirst = 0;
xlRef.val.sref.ref.rwLast = 0;
xlRef.val.sref.ref.colFirst = 0;
xlRef.val.sref.ref.colLast = 0 ;
Excel(xlfGetFormula, &xlFormula, 1, &xlRef);
This will restrieve the "=MyFunc(parameters)" in the xlFormula.val.str

You may have a try and let me know if this does the job for you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Date: Mon, 22 Sep 2003 14:09:09 -0400
From: Matthew Wieder
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4)

Gecko/20030624 Netscape/7.1 (ax)
X-Accept-Language: en-us, en, he
MIME-Version: 1.0
Subject: Excel4 Call to get Function String
References:




In-Reply-To:
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID:
Newsgroups: microsoft.public.excel.programming
NNTP-Posting-Host: 207.106.112.178
Lines: 1
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.excel.programming:418054
X-Tomcat-NG: microsoft.public.excel.programming

Yeah - I somehow combed ine net and discovered that same code segmant
which should do what I want, but the call to xlfGetFormula is failing
with a return code of 2 or "An invalid function number was supplied. If
you are using constants from XLCALL.H, this shouldn't happen." I checked
XLCall.h and xlfGetFormula is correctly defined as 106. I hope we can
solve this issue as it has become somewhat urgent for us.
thanks!

Rob Bovey wrote:

"Matthew Wieder" wrote in message
...

That is what I need, but I need the actual string, not aa version I can
reconstruct. The difference is that I need to know whether a single
cell was entered as "$B$1" or as "B1:B1" which are equivalent once the
become passed in as XLOPERS so I need to get the actual string from the
cell.



Hi Matthew,

I've never tried to do this, so I don't know for sure that there's a
solution. The following seems like it ought to work:

XLOPER xlRef, xlFormula;
Excel4(xlfCaller, &xlRef, 0);
Excel4(xlfGetFormula, &xlFormula, 1, &xlRef);

but in the quick tests I've done it doesn't. I'll play with it some more
when I get back home tonight. and post again if I can get it working.





Rob Bovey

Excel4 Call to get Function String
 
Hi Peter,

The problem is that Matthew is trying to get the function string from
within the function itself. As far as I can tell, xlfGetFormula does not
work when called from within a function and passed the address of the cell
(as returned by xlfCaller) from which that function was called.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Peter Huang [MSFT]" wrote in message
...
Hi Matthew,

e.g. You have a MyFunc in xll and at A1 you using the formula
"=MyFunc(parameters)"
Then you need to call the Excel4 after the MyFunc return.
Here is my code.
XLOPER xlRef, xlFormula;
xlRef.xltype=xltypeSRef;
xlRef.val.sref.count =1;
xlRef.val.sref.ref.rwFirst = 0;
xlRef.val.sref.ref.rwLast = 0;
xlRef.val.sref.ref.colFirst = 0;
xlRef.val.sref.ref.colLast = 0 ;
Excel(xlfGetFormula, &xlFormula, 1, &xlRef);
This will restrieve the "=MyFunc(parameters)" in the xlFormula.val.str

You may have a try and let me know if this does the job for you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Date: Mon, 22 Sep 2003 14:09:09 -0400
From: Matthew Wieder
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4)

Gecko/20030624 Netscape/7.1 (ax)
X-Accept-Language: en-us, en, he
MIME-Version: 1.0
Subject: Excel4 Call to get Function String
References:




In-Reply-To:
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID:
Newsgroups: microsoft.public.excel.programming
NNTP-Posting-Host: 207.106.112.178
Lines: 1
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.excel.programming:418054
X-Tomcat-NG: microsoft.public.excel.programming

Yeah - I somehow combed ine net and discovered that same code segmant
which should do what I want, but the call to xlfGetFormula is failing
with a return code of 2 or "An invalid function number was supplied. If
you are using constants from XLCALL.H, this shouldn't happen." I checked
XLCall.h and xlfGetFormula is correctly defined as 106. I hope we can
solve this issue as it has become somewhat urgent for us.
thanks!

Rob Bovey wrote:

"Matthew Wieder" wrote in message
...

That is what I need, but I need the actual string, not aa version I can
reconstruct. The difference is that I need to know whether a single
cell was entered as "$B$1" or as "B1:B1" which are equivalent once the
become passed in as XLOPERS so I need to get the actual string from the
cell.


Hi Matthew,

I've never tried to do this, so I don't know for sure that there's

a
solution. The following seems like it ought to work:

XLOPER xlRef, xlFormula;
Excel4(xlfCaller, &xlRef, 0);
Excel4(xlfGetFormula, &xlFormula, 1, &xlRef);

but in the quick tests I've done it doesn't. I'll play with it some

more
when I get back home tonight. and post again if I can get it working.







Matthew Wieder

Excel4 Call to get Function String
 
After doing as much research as I could (very limited with the weak web
resources on this topic) it seems that xlfCaller is a Level 2 Macro call
and can only be called from a Function registered with a # at the end of
the type_text. Pulling someone else's code, I created a small function
that gets the cell formula and passes it back in an XLOPER. I
registered that function with the # and then I use xlUDF to call it and
get the XLOPER it returns in my main code. For the time being,
everything seems to be working OK.
Thanks for your efforts.

Rob Bovey wrote:
Hi Peter,

The problem is that Matthew is trying to get the function string from
within the function itself. As far as I can tell, xlfGetFormula does not
work when called from within a function and passed the address of the cell
(as returned by xlfCaller) from which that function was called.




All times are GMT +1. The time now is 01:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com