Accessing the Taskpane from the Excel sheet

Add-in Express™ Support Service
That's what is more important than anything else

Accessing the Taskpane from the Excel sheet
 
Michael Hovdan




Posts: 37
Joined: 2010-06-26
Here is what I am trying to do: When the user types something in a cell, say in "A1", then I want the content to be copied to a TEdit component on my task pane through the SheetChange event. Something along these lines:

procedure TAddInModule.adxExcelAppEvents1SheetChange(ASender: TObject;
const Sh: IDispatch; const Target: ExcelRange);
begin
Taskpane.MyEdit.Text := Target.Value; {I know this doesn't work but you see what I'm trying to achieve, huh?}
end;

So the question is, how can I call the task pane from Excel?
Posted 10 Aug, 2013 04:53:53 Top
Michael Hovdan




Posts: 37
Joined: 2010-06-26
Seems like I found a way to do it. I defined a global variable called Taskpane, and initialized it in the TTaskpane's OnCre ate event:

procedure TTaskPane.adxExcelTaskPaneCreate(Sender: TObject);
begin
TaskPane:=TTaskpane(Sender);
end;

That seems to do exactly what I wanted. Probably not a good programming practice, but hey it works.
Posted 10 Aug, 2013 06:35:16 Top
Andrei Smolin


Add-in Express team


Posts: 15280
Joined: 2006-05-11
Hello Michael,

Excel 2013 is an SDI application and the manager will create an instance of your pane per Excel window. In this situation, the global variable above will be rewritten whenever you open an Excel workbook (or create a new Excel window for the same workbook).

procedure TAddInModule.adxExcelAppEvents1SheetChange(ASender: TObject;
  const Sh: IDispatch; const Target: ExcelRange);
var
  i: integer;
  count: integer;
  pane: TadxExcelTaskPane1;
begin
  pane := TadxExcelTaskPane1(adxExcelTaskPanesManager1.Items.Items[0].TaskPaneInstance);
  pane.SetEdit(Target.Value);
end;


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Aug, 2013 04:13:51 Top
Michael Hovdan




Posts: 37
Joined: 2010-06-26
Good point, Andrei. I see the problem. Thank you for the solution! :)
Posted 12 Aug, 2013 07:14:06 Top
Andrei Smolin


Add-in Express team


Posts: 15280
Joined: 2006-05-11
You are welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Aug, 2013 08:42:31 Top