我从三列数据创建了一个 xy 散点图——请参阅下面的数据示例和代码。代码从加载项运行,而不是从活动工作簿运行
放入SeriesCollection(1)
辅助轴后,将选择该图表线。根据 Excel 2007 HELP,ActiveChart.Deselect
应该取消选择所有内容。但是当添加到我的代码中时它什么也没做。 .Deselect
在自 Office XP 以来的对象模型更改中作为图表对象的一种方法列出,状态为hidden
.
我找到了各种建议,包括选择一些单元格;或使用 SendKeys 发送 {ESC}。唯一可行的方法是首先启用屏幕更新,然后保护图表。(unprotect after 不是去掉选择的必要,而是方便以后的工作)。
有没有更好的方法,或者这是一个合理的解决方法?
Chart.Deselect
可以在其他版本的 Excel 中使用吗?
最终结果应该是图表将在屏幕上可见,没有任何选择。
短数据样本
Time Amps Volts
04/26/2015 01:22:39 PM 4.9 53.4
04/26/2015 01:22:40 PM -0.9 53.2
04/26/2015 01:22:41 PM -1.5 53.4
04/26/2015 01:22:42 PM 8.7 53.4
04/26/2015 01:22:43 PM -2.9 53.3
04/26/2015 01:22:44 PM -3.2 53.2
04/26/2015 01:22:45 PM 11.3 53.8
04/26/2015 01:22:46 PM -3.8 53.3
04/26/2015 01:22:47 PM -3.2 53.3
04/26/2015 01:22:48 PM 11.4 53.6
04/26/2015 01:22:49 PM -3.2 53.3
04/26/2015 01:22:50 PM -2.8 53.2
04/26/2015 01:22:51 PM 5.7 53.3
04/26/2015 01:22:52 PM 7.5 53.5
04/26/2015 01:22:53 PM 2.1 53.3
04/26/2015 01:22:54 PM 2.3 53.4
04/26/2015 01:22:55 PM 2.5 53.3
04/26/2015 01:22:56 PM 2.4 53.4
04/26/2015 01:22:57 PM 2.3 53.4
04/26/2015 01:22:58 PM 1.9 53.5
04/26/2015 01:22:59 PM 2 53.3
04/26/2015 01:23:00 PM 2.3 53.3
04/26/2015 01:23:01 PM 2.7 53.5
04/26/2015 01:23:02 PM 2.5 53.4
04/26/2015 01:23:03 PM -2.4 53.4
04/26/2015 01:23:04 PM -4 53.3
04/26/2015 01:23:05 PM -3.5 53.3
04/26/2015 01:23:06 PM 4.1 53.4
04/26/2015 01:23:07 PM 9.4 53.6
04/26/2015 01:23:08 PM -5.1 53.3
04/26/2015 01:23:09 PM 9.8 53.6
04/26/2015 01:23:10 PM -5.2 53.2
04/26/2015 01:23:11 PM 9.7 53.5
04/26/2015 01:23:12 PM -5.5 53.2
04/26/2015 01:23:13 PM 9.8 53.6
使用此代码:
Sub GraphEmeter()
Dim cS As Chart
Dim A As Axis
Application.ScreenUpdating = False
Set cS = ActiveWorkbook.Charts.Add
Set cS = ActiveChart
With cS
.SetSourceData Range("capture!R1").CurrentRegion, xlColumns
.ChartType = xlXYScatterLinesNoMarkers
Set A = .Axes(xlCategory)
With A
.CategoryType = xlCategoryScale
.BaseUnitIsAuto = True
.TickLabels.Orientation = 45
End With
.SeriesCollection(1).AxisGroup = 2
'deselect the chart area
'documented method
' ActiveChart.Deslect
'doesn't seem to work
'But this method does
Application.ScreenUpdating = True
.Protect
.Unprotect
End With
End Sub