今日やったこと:マクロでエクセルのグラフの書式を変更する(不完全)

excel2010。職場のエクセルは新しくて別の書き方だった。とりあえず。

こういうグラフがたくさんあったとして
f:id:elve:20200911192548p:plain

一気にこの書式にする
f:id:elve:20200911192618p:plain

なお、グラフスタイルの適用などしてるとうまくいかない。よくわかっていないw
オレンジとしているのはテーマのカラーに依存するのでオレンジじゃないかもしれない(;´Д`)

Option Explicit
Sub setGraphs()
Dim marus As ChartObjects: Set marus = ActiveSheet.ChartObjects
Dim maru As ChartObject
Dim c, r
For Each maru In marus
maru.Select
With ActiveChart
 'グラフ全体をオレンジに
.SeriesCollection(1).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent6
.Solid
End With
 'グラフの線もオレンジに
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent6
End With
 '残り部分を透明に
.SeriesCollection(1).Points(2).Format.Fill.Visible = msoFalse
 'タイトル設定
.SetElement (msoElementChartTitleAboveChart)
c = .Parent.TopLeftCell.Column
r = .Parent.TopLeftCell.Row
.ChartTitle.Text = Cells(r, c - 4)
.ChartTitle.Format.TextFrame2.TextRange.Font.Size = 8
 'サイズ設定
ActiveSheet.Shapes(maru.Name).Height = Application.CentimetersToPoints(2.86)
ActiveSheet.Shapes(maru.Name).Width = Application.CentimetersToPoints(3.81)
 '背景透明
ActiveSheet.Shapes(maru.Name).Fill.Visible = msoFalse
End With
Next
End Sub

どのくらい面白かった?

星を押して送信してね

平均 0 / 5. Vote count: 0

是非フォローしてください

最新の情報をお伝えします

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です