More Excel equivilent questions

D

David Thielen

Hi;

How do I do the following in Excel?

1) Find out if the caret is in the text of a cell and if so, the range
selected in that text?

2) Find out if the caret has selected one or more cells and if so, what cells?

3) How do I get/set the text/formula, cell formatting, border, font,
comment, etc for a cell?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
J

Jialiang Ge [MSFT]

Hello Dave,
1) Find out if the caret is in the text of a cell and if so, the
range selected in that text?
Do you mean to detect if the workbook is in "edit mode" by "if the caret is
in the text of a cell"? According to the response of Excel Product team in
the thread
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=158493&SiteID=1,
Excel does not expose a direct method to detect if it is in edit mode. But
here is a trick for your reference:
http://www.codeproject.com/useritems/Excel_Edit_Mode.asp
When it is in "Edit Mode", most functions of Excel are disabled and VBA
macros are not allowed to run. If your add-in tries to get selected text by
caret in edit mode, it will pop out errors. Therefore, it is suggested to
disable your add-in when users start to edit the cell text.
2) Find out if the caret has selected one or more cells and if so, what
cells?
To get the cells being selected, we could use Application.Selection which
will return a Excel.Range object. Because users may choose non-adjacent
cells, there could be several Areas in the range. (Range.Areas
http://msdn2.microsoft.com/en-us/library/aa213698(office.11).aspx). In each
Area, we could iterate its Cells and get their positions with Range.Left
and Range.Top properties.
3) How do I get/set the text/formula, cell formatting, border,
font, comment, etc for a cell?
Each cell is a Range object.
http://msdn2.microsoft.com/en-us/library/aa174290(office.11).aspx
To set/get the text of a Range, we could use Range.Value2
http://msdn2.microsoft.com/en-us/library/aa215938(office.11).aspx or
Range.Value
http://msdn2.microsoft.com/en-us/library/aa215937(office.11).aspx property.
To set/get the formula, we could set the Formula property:
http://msdn2.microsoft.com/en-us/library/aa160254(office.10).aspx
To set/get the cell formatting and border, we could use NumberFormat
(http://msdn2.microsoft.com/en-us/library/aa224873(office.11).aspx),
ClearFormats method
(http://msdn2.microsoft.com/en-us/library/aa223829(office.11).aspx),
Range.Borders property.

Please let me know if you have any other concerns, or need anything else.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jialiang Ge [MSFT]

Hello Dave,

A possible work-around is to SendMessage
(http://msdn2.microsoft.com/EN-US/library/ms644950.aspx) WM_GETSEL to get
the current selection of text in a specified handle. But it may complicates
the solution. I am still waiting for Product team's response, to see if
they have better resolutions. Thanks for your patience.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top