3 列のデータから XY 散布図を作成します。以下のデータ サンプルとコードを参照してください。コードは、アクティブなブックからではなく、アドインから実行されます
SeriesCollection(1)
2 番目の軸に配置した後、そのグラフ化された線が選択されます。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