editing a range copied using CopyPicture

ikf_excel

New Member
Joined
Jun 8, 2016
Messages
1
Hello,
I am trying to create an picture inside of a chart object made of cells copied from a worksheet and shapes added to the chart. This is what my code looks like

Sub SaveImage(predictionTable As Range, forecastTable As Range, FileName As String)
Dim Cht As Chart, bScreen As Boolean, Shp As Shape
bScreen = Application.ScreenUpdating
Application.ScreenUpdating = False
Set Cht = Workbooks.Add(xlChart).Charts(1)
Cht.ChartArea.Clear
Cht.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 200, 50).TextFrame.Characters.Text = "Returns Table"
With Cht.Shapes(1)
.Left = 800
.Top = 0
.Name = "Returns Title"
End With


predictionTable.CopyPicture xlScreen, xlPicture
Cht.Paste
Dim nc As Integer: nc = Cht.Shapes.Count
With Cht.Shapes(nc)
.Name = "Returns Table"
.ScaleHeight 0.7, msoTrue
.IncrementLeft 200
.IncrementTop 50
End With

Cht.Export FileName, "JPEG", False
Cht.Parent.Close False
Application.ScreenUpdating = bScreen
End Sub


The code is fine if i run through it in Debug mode, however if i run it normally it gives mea an 'the index into the specified location is out of bounds' error, even though nc is in fact 2.
Somehow I am unable access the Picture I copyPaste into the chart...
The weird thing is that if i go through the code line by line in debug mode is works fine. Any suggestions on how to get around this/what is going on?
Thanks for your help,
ikf
 
Hi and welcome to the MrExcel Message Board.

Does it make any difference if you remove the line: Application.ScreenUpdating = False ?
 
Upvote 0

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