[英]VBA to exort chart from excel tab to specific folder and name file based on a name in a cell on a different worksheet
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"? 如何更改宏以在名为“数据”的工作表中的单元格Y3后命名文件?
I tried this: Filename = "C:\\Report\\" & Sheets("Data").Range("Y3") & ".jpg", FilterName:="JPG" and it did not work. 我试过这个:Filename =“ C:\\ Report \\”&Sheets(“ Data”)。Range(“ Y3”)&“ .jpg”,FilterName:=“ JPG”,它不起作用。
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? 我希望这将有助于使用其Value
属性限定单元格定义? 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. 当然,我也将使用Worksheets()
而不是Sheets()
,但是我很有趣。
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 "). 但是事实证明,它在没有.Value
情况下对我.Value
,因此单元格中的内容或工作表名称可能存在问题(例如,如果它实际上是“ Data”)。
And by the way, PNG is generally a better format to use for graphics like an Excel chart. 顺便说一下,PNG通常是一种更好的格式,可用于Excel图表之类的图形。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.