• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to paste height and width of chart from another sub

Hi team
I have prepared a two Custom-Ribbon buttons.
One to copy the formatting, height and width of chart.
and another to paste the same on other selected chart.

The problem is when I am using the PASTE button, it is not picking the height and width of the previous chart.

Please help in this.

I have attached the file.

Code:
Global shpae_height As Long
Global shpae_width As Long

Sub copy_format(control As IRibbonControl)
Dim cbject As ChartObject

If ActiveChart Is Nothing Then
    MsgBox "Please select chart"
Else
    shape_height = ActiveChart.Parent.Height
    shape_width = ActiveChart.Parent.Width
    ActiveChart.ChartArea.Copy
End If

End Sub

Sub paste_format(control As IRibbonControl)
If ActiveChart Is Nothing Then
    MsgBox "Please select chart"
Else
    ActiveChart.ChartArea.Select
    ActiveSheet.PasteSpecial Format:=2
    ActiveChart.Parent.Height = shape_height
    ActiveChart.Parent.Width = shape_width
End If
End Sub
 

Attachments

  • Macro File of Chart - Copy.xlsm
    28.9 KB · Views: 3
It is as simple as a spelling mistake

Your code is:
Code:
Global shpae_height As Long
Global shpae_width As Long

It should be:
Code:
Global shape_height As Long
Global shape_width As Long
 
Back
Top