Charts.Add Alternative

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
This code allows me to copy/paste an image onto a blank chart object and then save the image to my computer. One thing really annoying is it must add a sheet for the blank chart object and then paste the blank chart object onto the main sheet and then delete the chart sheet. Can someone help me rewrite this code. Thanks

I tried this but I getting an error..
Set OHLCChart = Wks.ChartObjects.Add(0, 0, 600, 300)



VBA Code:
Sub ExportMyPicture2()
Dim MyChart As String, MyPicture As String, FName As String
Dim PicWidth As Long, PicHeight As Long

Application.ScreenUpdating = False
MyPicture = ActiveCell.Value

Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
MyChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2)

With ActiveSheet
    With .Shapes(MyChart)
          .Width = 600
          .Height = 300
    End With

    .Shapes(MyPicture).Copy

    With ActiveChart
          .ChartArea.Select
          .Paste
    End With
    
    'FName = VBA.Environ("TEMP") & Application.PathSeparator & "MyPic.jpg"
    '.ChartObjects(1).Chart.Export FName
    .Shapes(MyChart).Delete
    '.Shapes(MyPicture).Delete
     'Kill FName
End With
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
When I try replacing this part of the code..

VBA Code:
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
MyChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2)

With ActiveSheet
    With .Shapes(MyChart)
          .Width = 600
          .Height = 300
    End With

With

VBA Code:
Set OHLCChart = Wks.ChartObjects.Add(0, 0, 600, 300)
 
Upvote 0
Again, what error? ;)
 
Upvote 0
1603109108492.png


The error occurs Set MyChart = ActiveSheet.ChartObjects.Add(0, 0, 600, 300)

VBA Code:
Sub ExportPic()
Dim MyChart As Object, MyPicture As String, FName As String
Dim PicWidth As Long, PicHeight As Long

Application.ScreenUpdating = False
MyPicture = ActiveCell.Value

Set MyChart = ActiveSheet.ChartObjects.Add(0, 0, 600, 300)

With ActiveSheet

    .Shapes(MyPicture).Copy

    With ActiveChart
          .ChartArea.Select
          .Paste
    End With
 
Upvote 0
Is the active sheet protected?
 
Upvote 0
Which version of Excel?
 
Upvote 0
I can't replicate the error in 2016.
 
Upvote 0

Forum statistics

Threads
1,214,596
Messages
6,120,438
Members
448,966
Latest member
DannyC96

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