Copilot for Microsoft 365 Tech Accelerator
Feb 28 2024 07:00 AM - Feb 29 2024 11:00 AM (PST)
Microsoft Tech Community

RTD EXCEL user defined data type, e.g. Employee with Name and Age

Copper Contributor


I have been trying to write an RTD com server in C++ to display the user defined data. My question here is: Could we send a user defined data type, i.e. Employee, from the RTD server in the callback and unpack in the VBA code?



struct Employee {
   int age;
   std::string name;





HRESULT CNAHERTDServer::RefreshData(long * topicCount, SAFEARRAY * * parrayOut) {
  //it works
  value.vt = VT_BSTR;
  _bstr_t bstrt(itr->second.c_str());
  value.bstrVal = bstrt;
  SafeArrayPutElement(*parrayOut, index, &value);


VBA code: //get employee here, unpack and put in the excel



Private Sub Worksheet_Calculate()
  Dim changedRange As Range
  On Error Resume Next
  Set changedRange = Range("Lookup!tbData")
  On Error GoTo 0

  If Not changedRange Is Nothing And changedRange.Count = 1 Then
    Debug.Print changedRange.value
  End If
End Sub



0 Replies