I currently have an excel vsto solution that has an action pane consisting of link labels. There is code behind the link label click event to select a particular range in the worksheet. When you click the link label, it selects the range on the worksheet correctly, but if I start typing immediately, I realize the focus is on the action pane, not on the excel worksheet. Is there a method in excel that will explicitly pass the focus to the worksheet range

Select worksheet explicitly
rjr
Hmmm... did some 're'-testing as it didn't work for you. I noticed I had a breakpoint on the Select() line that caused the code to work after hitting the F5 again.
The VB equivalent:
Dim ws As Excel.Worksheet = Globals.ThisWorkbook.ActiveSheet
Dim range As Excel.Range = ws.Range("B2")
range.Select()
ws.Activate()
That last line is supposed to activate the worksheet. (C# needed some weird casting to eliminate the warnings here...)
But... unless you hit the breakpoint like I did, it isn't going to work.
So... I guess there is no other option than the 'flicker' option Steve gave earlier. It's a sad thing...
That would be something like this:
Dim ws As Excel.Worksheet = Globals.ThisWorkbook.ActiveSheet
ws.Range("B2").Select()
ws.Application.CommandBars("Task Pane").Visible = False
ws.Application.CommandBars("Task Pane").Visible = True
-= Maarten =-
Michael Nebel
This did not work for me.
Can you post vb equivalent code for the same, What is the last line in the code doing
Robert_Jr
This may not be the "preferred" method, but it works. In your link label click event, after you select the desired range, add the following code:
Globals.ThisWorkbook.Application.CommandBars["Task Pane"].Visible = false;
Globals.ThisWorkbook.Application.CommandBars["Task Pane"].Visible = true;
Granted, this feels like a hack and produces a minor flicker. Anyone got a better way
Thanks,
Steve
Sajal
I did some testing for you and it looks like you need to use Activate() on the worksheet that is containing the range you selected to move the focus from the ActionsPane to the worksheet.
This way you can start typing right after you selected the range.
private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Excel.Worksheet ws = (Excel.Worksheet) Globals.ThisWorkbook.ActiveSheet;
Excel.Range range = ws.get_Range("A1", Type.Missing);
range.Select();
((Excel._Worksheet) ws).Activate();
}
-= Maarten =-