format mutiple charts via VBA

Access Beginner

Active Member
Joined
Nov 8, 2010
Messages
311
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I have 23 Charts on a sheet which I place into a MS Word Doc. ATM all charts have borders, which is what one of my Managers like, however another Manger likes these charts without borders. I tried to record a macro so I could have this done by VBA (excel 2007) but it did not record the formatting. Can someone please write a code to remove a border and and then add a border back in specifying colour, border styles (width etc). Say just for Chart 38, I can the just repeat this. But here are all the chart numbers in case you need them: 38,20,27,5,11,21,13,6,9,19,10,7,28,29,30,31,32,12,33,34,37,35 & 36.

Cheers
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi

This is an example that changes the border to vbRed and weight 4 in the charts "Chart 1", "Chart 3" and "Chart 4" in worksheet "Sheet1".

Code:
Sub ChangeChartBorder()
Dim chtObjs As ChartObjects
Dim vIndices As Variant, vIndex As Variant

Set chtObjs = Worksheets("Sheet1").ChartObjects

vIndices = Array(1, 3, 4)

For Each vIndex In vIndices
    With chtObjs("Chart " & vIndex).Border
       .Color = vbRed
       .Weight = 4
    End With
Next vIndex

End Sub

HTH
 
Upvote 0
Hi

This is an example that changes the border to vbRed and weight 4 in the charts "Chart 1", "Chart 3" and "Chart 4" in worksheet "Sheet1".

Code:
Sub ChangeChartBorder()
Dim chtObjs As ChartObjects
Dim vIndices As Variant, vIndex As Variant

Set chtObjs = Worksheets("Sheet1").ChartObjects

vIndices = Array(1, 3, 4)

For Each vIndex In vIndices
    With chtObjs("Chart " & vIndex).Border
       .Color = vbRed
       .Weight = 4
    End With
Next vIndex

End Sub

HTH
Thanks for that I will test this out tomorrow at work. Cheers
 
Upvote 0

Forum statistics

Threads
1,223,996
Messages
6,175,869
Members
452,679
Latest member
darryl47nopra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top