FullSeriesCollectionメソッドを使用してグラフのさまざまなプロパティを取得または設定しようとしているときに、インデックスやシリーズ名でアクセスできますが、変数に格納された名前を使用しようとすると、実行時エラー13(型の不一致)が発生します。たとえば:変数に格納された名前を使用してFullSeriesCollectionにアクセスすると、Excel VBAランタイムエラーが発生する
Dim trendname As String 'I've also tried Variant, but it still gives me error 13
trendname = "Average" 'when the name is used directly as below
Debug.Print Charts(1).FullSeriesCollection(1).Formula 'This works
Debug.Print Charts(1).FullSeriesCollection("Average").Formula 'This works
Debug.Print Charts(1).FullSeriesCollection.Item("Average").Formula 'This works
Debug.Print Charts(1).FullSeriesCollection(trendname).Formula 'This gives runtime error 13
Debug.Print Charts(1).FullSeriesCollection.Item(trendname).Formula 'This gives runtime error 13
Debug.Print Charts(1).FullSeriesCollection("" & trendname).Formula '...but this works fine!
Debug.Print Charts(1).FullSeriesCollection.Item("" & trendname).Formula 'This works too
は、私はそれだけではtrendnameを参照するのではなく、空の文字列と変数を連結する必要が動作するように得ることができる方法はありますか? VariantやStringの代わりにtrendnameを宣言しなければならない別の変数型はありますか? 連結メソッドは機能しますが、むしろ愚かに見えますが、変数を単独で使用しているときになぜ機能するのか不思議です。
ありがとうございます!私は変種がそんなに限られているのか分からなかった。これは、私を悩ませている他のものと一緒に私を助けてくれるでしょう。 – Cary