Reputation: 93
Is there a way to access controls from a custom task pane when creating event handlers in the "ThisAddIn.cs" file?
I want to allow the user to either enter a cell reference manually, or just click on a cell and have that reference value show up in the text box on my user control. I'm unsure how to actually access my controls within an event handler.
I would have thought it'd have been as simple as just
myUserControl.txtMyTextBox.Text = active cell
I've been googling, but feel I may not be using the correct terminology.
Any help would be greatly appreciated!
EDIT: Here is some actual code. My wording is never the best.
namespace MyExcelAddin
{
public partial class ThisAddIn
{
private userCtrl myUserCtrl = new userCtrl();
public Microsoft.Office.Tools.CustomTaskPane tskPaneUsers;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
tskPaneUsers = this.CustomTaskPanes.Add(userCtrl, "My Control");
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
void ThisAddIn_SheetSelectionChange(object sender, Excel.Range Target)
{
//This is where I want to access my textbox inside my usercontrol.
// Is it out of scope?
}
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
Application.SheetSelectionChange += new Excel.AppEvents_SheetSelectionChangeEventHandler(ThisAddIn_SheetSelectionChange);
}
Upvotes: 0
Views: 1622
Reputation: 4929
You can access the current excel components via the Excel.Application
object.
You can initialize it during your add-in loading process as ThisAddIn.Application
property.
Once you have access to the Excel.Application
object, you can use it to reference the active sheet and cell similar calls to
ThisAddIn.Application.ActiveCell.Row
ThisAddIn.Application.ActiveCell.Column
you can also convert the Row
and Column
properties to String
and combine them into your TextBox text.
Was this helpful?
Upvotes: 1