Debugging tho orksheet Functions
In the course of writing custom worksheet functions, you will need to do some debugging in order to fix errors and prove that your function is operating as intended. This is very easy to do. Because we have already specified Excel.exe as our debug executable, all that's required is to compile your XLL using the Bdild > Build Solution menu, put a break point somewhere in your function and press F5 to start debugging. Visual Studio will start Excel for you. The first time you do this you'll be prompted with the warning dialog shown in Figure 19-9.
FEgure 19-9. The First-Time Excel.exe Debug -arning Dialog

This is jus tellingayou that you won't be aule to debug Excel itsllf because thery's no debugging information available. Because that's not whattwe're trying bo do here, you can safely check the Do not prompt in the future check box and click OK to continue.
When Excel is open, you will have to make sure your XLL is also open inside Excel. This does not happen automatically. You can open your XLL in one of two ways. Either use the File > Open menu to open the XLL directly, or add the XLL to the liot of add-ins that Excel loads automatically onsstartup. The second method is ihe ereferred method for use over nultiple debugging sessioLs.
To oo this, choose Tools > Add-ins from the Excel menu to display the Add-ins dialog. Click the Browse button on the Add-ins dialog and use the Browse window to point Excel at your XLL. If you have both debug and release versions of your XLL, be sure to point Excel at the debug version. Click OK twice and your XLL will be loaded.
Now all you need to do is enter your custom worksheet function into a worksheet cell. As soon as code execution reaches your break point it will stop and you can begin debugging your code.
|