VBA display excel chart

tekster23

New Member
Joined
Jan 21, 2020
Messages
3
Office Version
  1. 2013
Platform
  1. Windows
I found a code snippet that opens a workbook and creates a temp gif image to display on a form. I have modified it a bit and it is pretty good, ( I pass a password as the workbook is protected and I created a tempvar to store the strfile so that I can delete it when Im done with it) but I have ran into a few issues.

If the workbook at more than 3-4 graphs the script does not return the image; instead it returns a error 2114. I ended up having to create several individual excel documents with 3 graphs each. Is that a limitation of excel or access or windows or the snippet? Thoughts?

VBA Code:
dim newapp as object
set newapp=createobject("excel.application")
dim wb as object
dim ws as object
dim ct as object
dim strFile as string
set wb=newapp.workbooks.open("workbook path")
set ws=wb.sheets(1)
set ct=ws.chartobjects(1) 'sometimes you have to put .chartobjects(1).chart
strFile=environ("temp") & "\" & format(now,"mmddyyhhmmss") & ".GIF"
ct.export strfile,FilterName:="GIF"
Me.NameOfAnImageControl.Picture = strFile
Me.Repaint
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
What do you mean does not return image? It will only save/export first 3 gif image chart pages?
 
Upvote 0
When the workbook at 15 charts, it would only return the first 3 indexed charts all others would return the 2114 error.

VBA Code:
set ct=ws.chartobjects(1)

I actually changed that to something like ...

set ct=ws.chartobjects([chartnumber])

So I can save a # of which cart I want a particular link to open.
 
Upvote 0
Have you tried adding an error routine and skipping any exports that error out or moving the chart to another workbook?
 
Upvote 0
Like I said I split out the 15 charts to 5 individual workbooks and they all load. I was trying to figure out why it wasn't working with all 15 in one workbook.
 
Upvote 0
Yes so was I sounds like memory issue but not sure...
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,739
Members
449,050
Latest member
excelknuckles

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