?
Solved

run macro on selected charts (resizing the chart area as well as data labels)

Posted on 2014-01-20
4
Medium Priority
?
2,143 Views
Last Modified: 2014-01-23
Dear Experts:

for the selected charts on the active worksheet I would like to run the following VBA macro:

- Resize the charts to Width of 5 cm and Height of 9 cm
- Increase the size of the chart labels (all of them are pie charts) to 10 pt and font type 'Times New Roman'

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
  • 2
  • 2
4 Comments
 
LVL 54

Expert Comment

by:Rgonzo1971
ID: 39794807
Hi,

pls try

Sub Makro7() '
' Makro7 Makro
For Each wks In Workbooks
    wks.Activate
    For Each cht In ActiveSheet.ChartObjects
        'cht.Legend.Format.TextFrame2.TextRange.Font.Size = 10
        cht.Chart.SeriesCollection(1).DataLabels.Format.TextFrame2.TextRange.Font.Size = 10
        cht.Chart.ChartArea.Height = Application.CentimetersToPoints(5)
        cht.Chart.ChartArea.Width = Application.CentimetersToPoints(9)
    Next
Next
End Sub

Open in new window

Regards
0
 

Author Comment

by:AndreasHermle
ID: 39797209
Hi Rgonzo,

thank you very much for your swift help. I will give your code a try soon, but as I can see all of the charts get worked on on the active worksheet.

I got charts on the active worksheet that should be left alone and only those charts that I selected by using the Shift-Key and clicking on them should be worked on. Is this possible, i.e. running the above macro just on selected charts ...

Regards, Andreas
0
 
LVL 54

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39797360
Hi,

pls try

Sub Makro7() '
' Makro7 Makro

For Each cht In Selection
    cht.Activate
    'cht.Legend.Format.TextFrame2.TextRange.Font.Size = 10
    cht.Chart.SeriesCollection(1).DataLabels.Format.TextFrame2.TextRange.Font.Size = 10
    cht.Chart.ChartArea.Height = Application.CentimetersToPoints(5)
    cht.Chart.ChartArea.Width = Application.CentimetersToPoints(9)
Next

End Sub

Open in new window

It is without test whether you select Charts or anything

Regards
0
 

Author Closing Comment

by:AndreasHermle
ID: 39804628
Great, this did the trick. Thank you very much for your professional help. Regards,  Andreas
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question