VBA to copy/paste a chart

andygill

New Member
Joined
Feb 18, 2008
Messages
7
Hello

Could you help me.

I have some vba code that copies a chart as a picture to a sheet called destination.

The code runs in a loop updating the chart and coying to destination for each line of data (30 lines).

Everytime I run the code at random points in the process (that is not the same graph each time).

I get either runtime error Method copy of object 'ChartArea' failed at the line ActiveChart.ChartArea.Copy or

or runtime error '1004' Unable to get the pastespecial property of the worksheet class at the line ws = ActiveSheet.PasteSpecial(Format:="Picture (PNG)", Link:=False, DisplayAsIcon:=False).

If I click on the debug and then run sub button I carries on with the process of copying the graphs.

I've attached my code.

Thanks for your help.
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    219 KB · Views: 494
Probably i can change the name of chart before in other Sub(), seting ".Name = "MATIC"" ,but i get the error 7 (insuficient memory). Remains pending insert the code to delete chart before insert new pic.

With ws.Shapes.AddChart.Chart '' Excel 2007+
''With ws.Shapes.AddChart2.Chart '' Excel 2013 only

'' chart type
.ChartType = xlLineMarkers

'' chart data
.SetSourceData Source:=ws.UsedRange

'' Change chart title
.ChartTitle.Text = Range("B3")

'' Name
.Name = "MATIC"
End With


I´ve try to subdivide the code in two Moduls, and the principal Modul (Import_Chart_G_Trends,call in his final code to other Modul (Módulo 1)
1642346737333.png

¿What cause problem do you think is?
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
In your code, .Name is referring to the Chart object. Try referring to the Shape object instead by using the Parent property of the Chart object. . .

VBA Code:
.Parent.Name = "MATIC"
 
Upvote 0
Yeeees! Thats fuction. Ty.

Respect the obtain the csv, as change the name of the csv each moth in website, i need click in bottom to download it using Selenium. The data is:
1642464070181.png


Im trying to do the code and obtain the error 424 (object required) mark in yellow the FindElement(By.XPath row.

1642464174496.png


Sub ClickButton4()

Dim driver As New Selenium.ChromeDriver

With driver

driver.Get "https://trends.google.es/trends/explore?q=MATIC"

Application.Wait (Now + TimeValue("00:00:05"))

.FindElement(By.XPath("//i[@class='material-icons-extended gray']")).Click

End With

Set driver = Nothing


Some sugestions?
 
Upvote 0
Sorry, I'm not familiar with Selenium.

In any case, whenever you have a new question you should start a new thread. So I would suggest that you start a new one.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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