Fairly straightforward scenario, for which I can’t seem to find an answer anywhere:
- I am using a Microsoft WebBrowser
ActiveX control (AxSHDocVw.AxWebBrowser) in a Windows Forms
application. - The WebBrowser control
is used to display Excel workbooks in
the application. - I can obtain a
reference to the internal document as
a
Microsoft.Office.Interop.Excel.Workbook. - What I cannot seem to find, despite
hours of searching the Web, is any
reliable guidance on how to determine
the range of cells currently selected
by the end-user.
Here’s the problem. Since the sheet is displayed in the browser, it doesn’t have the Excel toolbar displayed, and I’d like to provide at least some rudimentary functionality (cut, copy, paste, undo, redo, bold, italic, underscore, left, right, center, and so on) from my application’s main window. In order to do that, I need to be able to forward those commands onto the active sheet. Some of those commands require knowledge of the currently selected range if I want to properly execute them.
If anyone knows how to do this, I would be forever in your debt. (Well, maybe not forever, but you get the point.)
[NOTE: I use the old ActiveX control so that I can trap the NavigateComplete2 event to capture the reference to the internal document. The .NET WebBrowser control doesn’t expose this functionality the same way.]
If you can get the workbook reference, you should be able to do .Application.Selection to get the current selected Range.