Need to deselect a chart on a chart-sheet in Excel 2007. Just clicking anywhere with the mouse does it. How do I do this in VBA?
If I record the 'click anywhere' action, I get nothing captured in VBA-code. Setting "Activewindow.Visible=False"is a known bug in 2007 and does not work. I tried ActiveChart.Deselect but that doesn't work too.
I can write code to prevent the chart from being selected, but I'd like my code to fix this anyway; maybe the user selected the chart manually, then I want to unselect.
Any ideas?
This works but I don't like it... SendKeys "{ESC}", TRUE
Deselect Chart in 2007
-
- BronzeLounger
- Posts: 1255
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
-
- Administrator
- Posts: 78549
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Deselect Chart in 2007
Clicking "anywhere" with the mouse usually results in selecting something - if not a series or axis, then the chart's plot area or chart area. What exactly do you mean by deselect?
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1255
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Deselect Chart in 2007
When I click outside the chart-area all gets deselected.
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78549
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Deselect Chart in 2007
Thanks. There doesn't seem to be any support for this, so the only thing I can come up with is the rather lame
Remark: this only works when run from Excel. If you run this from the Visual Basic Editor, the keystroke is sent to the VBE instead of to the chart.
Code: Select all
ActiveChart.ChartArea.Select
SendKeys "{ESC}"
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1255
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Deselect Chart in 2007
See my original post... it's there (I found that and had updated the post before the first answer already) :-)
-
- Administrator
- Posts: 78549
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Deselect Chart in 2007
Sorry, I hadn't noticed the update. The screenshots in your reply had caused the original post to scroll off the screen.
I don't like SendKeys either, but I can't think of or find a better way.
I don't like SendKeys either, but I can't think of or find a better way.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 817
- Joined: 24 Jan 2010, 15:56
-
- BronzeLounger
- Posts: 1255
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Deselect Chart in 2007
Very interesting... that actually works! Thank you, I would have never figured that one outrory wrote:Does it work if you protect and then unprotect the chart?