Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# COM Excel VBA
Hi TechGurus,
 
I have overwritten the Excel and doing multiple manipulations based the selected object.
I am getting the correct selected object by using the application.selection property
object selectedObj = _xlApp.ActiveWindow.Selection;
and based on the selected object I am checking if the selected object is not a Range object then call the default windowProc so that Excel can handle those messages.
if (!(selectedObj is MsExcel.Range))
{
      base.WndProc(ref msg);
      handled = true;
}
But, due to instruction: object selectedObj = _xlApp.ActiveWindow.Selection;
I am not able to resize the size of comment window in Excel.
 
Please suggest some other method through which i can get the selected object.
 
Thanks in Advance.
 
- virenk
Posted 28-Mar-13 0:48am
Edited 28-Mar-13 0:51am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to reference to the cell/range, which you want to use later:
In pseudocode:
Excel.Workbook Wbk = _xlApp.Workbooks.Open("fullfilename")
Excel.Worksheet Wsh = Wbk.Worksheets(index)
Excel.Range Rng = Wsh.Range("A1")
 
if (Rng.Value2 == 5)
{
     //do something
}
  Permalink  
Comments
Virendra_ec10 at 28-Mar-13 6:20am
   
Hi Maciej Los,
 
Thanks for your quick reply.
I need to know if the current selected object is not a Range object(For example if the current selected object is comment box) then call the default windproc.
Can you please help to get the current selected object without using the selection property.
 
Thanks,
virenk
Maciej Los at 28-Mar-13 6:30am
   
I'm not sure what you mean... Please, explain what you are trying to achieve and share your code. What is a comment box?
Virendra_ec10 at 28-Mar-13 6:43am
   
In Excel Right Click on any cell->select "Insert comment" from the option menu it opens comment box. I don't want to override any message that comes from the resizing or editing of comment box. So, I am trying to handle like this:
object selectedObj = _xlApp.ActiveWindow.Selection;//problamatic line want to replace with some other method
 
if (!(selectedObj is MsExcel.Range))
{
base.WndProc(ref msg);
handled = true;
}
Maciej Los at 28-Mar-13 6:47am
   
Still i don't get what you are trying to achieve...
Virendra_ec10 at 28-Mar-13 7:43am
   
I just want replacement of _xlApp.ActiveWindow.Selection.
Maciej Los at 28-Mar-13 7:47am
   
What kind of replacement???
If you want my help, please,be more specific and provide more details...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 545
1 Kornfeld Eliyahu Peter 407
2 Maciej Los 369
3 DamithSL 221
4 OriginalGriff 218
0 OriginalGriff 6,383
1 DamithSL 4,879
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,056
4 Sergey Alexandrovich Kryukov 3,927


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100