reading named ranges with macro

Mar 5, 2013 at 3:58 PM
Edited Mar 5, 2013 at 4:06 PM
hi Keith,

hope you are doing well. I was trying to read named ranges using your example. I was looking at one of the previous discussions and came across your suggestions.

i am using the simple code below

static AddInX xai_macro1(_T("?xll_macro1"), _T("MACRO1"));
void WINAPI
xll_macro1(void)
{

pragma XLLEXPORT

OPERX H8 = ExcelX(xlfTextref, OPERX(_T("H8")), OPERX(true));
OPERX o = ExcelX(xlCoerce, H8);
ExcelX(xlcAlert, ExcelX(xlCoerce, H8));
}
I put some values in cell H8 of excel; and i observe o.xltype=256. and i get an empty box for xlcAlert (just like the other user find in one of the previous discussion). It would be kind of you to comment on this error.

best
Coordinator
Mar 5, 2013 at 4:07 PM
Macro functions return an int. 1 for success, 0 for failure. Fix that and try again.
Mar 6, 2013 at 3:08 PM
thanks for your reply,
i observe that if i put

OPERX H8 = ExcelX(xlfTextref, OPERX(_T("H8")), OPERX(true));

i get the blank result, but if i put

OPERX H8 = ExcelX(xlfTextref, OPERX(_T("Sheet1!H8")), OPERX(true));

i get the intended result.

is there anyway i can specify to look at the "active sheet"

best
Coordinator
Mar 6, 2013 at 3:15 PM
Have you tried OPERX(_T("!H8"))?
Mar 6, 2013 at 3:47 PM
yes and that does not work
Apr 5, 2013 at 9:43 PM
Dear Keith,
I am back with another issue for me. I already know how to work with named ranges and create OPER with reference to sheet I need.

But now I tried to read namedrange where row is higher then 0xFFFF and I have problem, I thought that I can use always OPERX to cover any version of excel.

so to simlyfy I tried this code
    OPERX o(72380,1,1,1);
    ExcelX(xlcAlert, ExcelX(xlCoerce, o));
and I have this error:

Error 1 error C2220: warning treated as error - no 'object' file generated macro.cpp 34 1 XllProjectTEST
Warning 2 warning C4305: 'argument' : truncation from 'int' to 'unsigned short' macro.cpp 34 1 XllProjectTEST
Warning 3 warning C4309: 'argument' : truncation of constant value macro.cpp 34 1 XllProjectTEST

I have VS2010Pro and Excel2007.

many thanks for your time,
BR,
L.
Apr 5, 2013 at 11:07 PM
I thing I can solve it like this:
            OPER12 oOPER12(72380,1,1,1);
            Excel<XLOPER12>(xlcAlert, Excel<XLOPER12>(xlCoerce, oOPER12));
but still I would like to understand if and so how use OPERX for this if possible.

best
L.
Coordinator
Apr 6, 2013 at 1:15 AM
You are correct. I followed the lead in the Microsoft SDK and use OPER and OPER12 in the same way they use XLOPER and XLOPER12.

Since I work hard to be lazy, I wanted to be able to write code that would work with both the old and new versions. If you use OPERX then you can control the version by #defining EXCEL12 before you include "xll/xll.h". Your code in your previous post should work if you do this.

You can use the xll::traits class to detect if the you are exceeding the pre Excel 2007 limits. https://xll.codeplex.com/SourceControl/changeset/view/20952#134557