Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can you help me,Now
According Guide to Writing Custom Functions in Excel: Part II Automation Add-In[^]
When I input the User defined function to the Excel selected cell,Only the selected cell receive value. but I want to change the other cells when I input the UDF. According to the VBA Excel User defined Function,Which code following:
VB
Module 
Function Owndefine(a)
      Owndefine = a*10
      Set myc = new css
      Set myc.sht = ActiveSheet
End Function

class module css 
Public WithEvent sht As Worksheet
Private Sub sht_change(ByVal Target As Range)
    On Error GoTo ren
    Set  myc.sht = Noting
    Set  myc     = Nothing
    Range("a1:b3) = 1
  ren:
End Sub

The VBA UDF add an Event,So which can change the other cells when inputing the UDF.I want to realize it in C++,can you give some help,thank you .
Posted
Updated 30-Jul-13 23:25pm
v2
Comments
The_Inventor 15-Aug-13 22:59pm    
First you need to know the subtle differences in syntax between what I see above and C++.

VB
SINK_ENTRY_INFO(11, __uuidof(MSExcel::AppEvents), 0x61C, &SheetChange, &SheetChangeInfo)
    SINK_ENTRY_INFO(12, __uuidof(MSExcel::WorkbookEvents), 0x61b, &SheetCalculate, &SheetCalculateInfo)


Copy the VBA menthod,In the C++ ,I Use the EVNET to get the UDF.That's OK.
 
Share this answer
 
BEGIN_SINK_MAP(CAddin)
SINK_ENTRY_INFO(1, __uuidof(_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickBtnCwbb, &OnClickButtonInfo)
SINK_ENTRY_INFO(11, __uuidof(MSExcel::AppEvents), 0x61C, &SheetChange, &SheetChangeInfo)
SINK_ENTRY_INFO(12, __uuidof(MSExcel::WorkbookEvents), 0x61b, &SheetCalculate, &SheetCalculateInfo)
END_SINK_MAP()
// IAddin
public:
// _IDTExtensibility2
void _stdcall SheetCalculate(IDispatch *aa);
void _stdcall SheetChange( IDispatch* Sh, Range* Target);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900