I have a macro that exports a chart as an image to a specific folder, but it gives a fixed name. How can I change the macro to name the file after cell Y3 in a sheet named "Data"?
I tried this: Filename = "C:\\Report\\" & Sheets("Data").Range("Y3") & ".jpg", FilterName:="JPG" and it did not work.
Sub ExportGraphImage()
Worksheets("CIS Graph").ChartObjects(1) _
.Chart.Export _
Filename:="C:\Report\CISgraph.jpg",FilterName:="JPG"
End Sub
I expected that it would help to qualify the cell definition with its Value
property? The following worked for me (as did the original command). Of course, I also would use Worksheets()
instead of Sheets()
, but I'm funny that way.
Filename = "C:\Report\" & Sheets("Data").Range("Y3").Value & ".jpg", FilterName:="JPG"
But as it turns out, it worked for me without .Value
, so maybe there is a problem with what's in the cell, or the name of the sheet (like if it's really "Data ").
And by the way, PNG is generally a better format to use for graphics like an Excel chart.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.