Trapping Keys

Feb 25, 2012 at 4:59 PM

Just trying to trap keys without much joy. I had a look at on.h file and noticed the 

On ok("shortcut", "MACRO");

 class has been commented out which i uncommented, but getting the following error

1>c:\program files\kalx\xll\xll\on.h(53): error C2664: 'xll::Auto::Auto(xll::Auto::macro)' : cannot convert parameter 1 from 'OPER' to 'xll::Auto::macro'

Please let me know what's wrong with my macro.

static AddInX xai_format_date(_T("?xll_format_date"), _T("XLL.DATE"));



	return 1; // or 0 on failure

On<Key> format_date("^+d", "XLL.DATE")
Feb 25, 2012 at 7:59 PM

Hi Eric,

If you update the head revision this should work now. It does not work when EXCEL12 is defined. Yet.

Feb 26, 2012 at 6:15 PM

Thanks Keith.

Seem now to get link issues. see below.

1>function.obj : error LNK2001: unresolved external symbol "class Reg::Object xll_alert_level12" (?xll_alert_level12@@3V?$Object@_WK@Reg@@A)
1>macro.obj : error LNK2001: unresolved external symbol "class Reg::Object xll_alert_level12" (?xll_alert_level12@@3V?$Object@_WK@Reg@@A)
Feb 26, 2012 at 6:33 PM

Sounds like you don't have the latest code. I put xll_alert_level in a shared segment so that all add-ins could access it.

Do a fresh checkout and let me know if you still have problems.

Feb 27, 2012 at 11:23 AM
Edited Feb 27, 2012 at 12:35 PM

Thanks Keith. That worked.

Please point me in the right direction on calling excel commands:

As an example, i would like to format a selection to date. I'm getting runtime errors when i try the following.  I suspect my calling convention is lacking parameters, but not sure where.

 ExcelX(xlcFormatNumber,Excel(xlfSelection), OPERX(_T("dd/mm/yyyy"))); //format number to date
Feb 27, 2012 at 1:01 PM
Edited Feb 27, 2012 at 1:15 PM

I am assuming you already know about the Rosetta Stone for macros:

My guess is that xlfSelection is coming back as xltypeSRef. Use xlCoerce to get the value in the cell.

On second thought, you seem to be trying to format a cell in the sheet, not an OPER in memory. In that case you have to select the cell, then call xlcFormatNumber. There are examples of how to do this in the xllutility project on codeplex. See document.h and document.cpp.

Feb 27, 2012 at 1:42 PM

it's still not easy translating "The Rosetta Stone" into xll code, especially if the easiest of commands fail. Documentation in xll development in general can be improved especially for people wetting their feet.

Okay i figured( that for the current selection, the following should work, but still get runtime errors.

ExcelX(xlcFormatNumber,OPERX(0), OPERX(1), OPERX(_T("dd/mm/yyyy")));

Feb 27, 2012 at 2:00 PM

Welcome to the wonderful world of xll programing. Time to put on your daddy shoes.

ExcelX returns two values: an int for the call to ExcelX and the result of the function number as an OPER. The int code will throw a runtime error telling how the ExcelX called failed. I believe xlcFormat only takes one argument.

Feb 27, 2012 at 2:18 PM

Done. Now i know! - Trial & error

In case anyone asks, fixed by:

ExcelX(xlcFormatNumber, OPERX(_T("dd/mm/yyyy"))); // formats the current selection