简体   繁体   English

VBA根据不同工作表上单元格中的名称将图表从excel选项卡中拉到特定的文件夹和名称文件

[英]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.

相关问题 Excel VBA循环文件夹,并检查Excel文件名是否等于工作表 - Excel VBA loop folder and check if Excel file name is equal to worksheet 将工作表的选项卡名称链接到excel中的单元格 - link tab name of a worksheet to a cell in excel 工作表选项卡名称更改基于单元格值 - Worksheet Tab name change based on cell value 嵌套循环-VBA-复制工作表名称与特定文件夹中的文件名匹配的每个工作表 - Nested Loop- VBA- Copy each worksheet where the worksheet name matches file name in specific folder VBA 代码 Excel 从选项卡中提取特定单元格值到不同 Excel 文件上的表中 - VBA code Excel extract specific cell value from a tab into a table on a different Excel file 使用宏从单元格将Excel工作表保存为CSV文件格式的CSV文件 - Saving excel worksheet to CSV with file name from a cell using a macro Excel VBA:将excel列从一个文件复制到相同名称的另一个文件(在不同文件夹中) - Excel VBA: copy excel columns from one file to other file (in different folder) of same name 如何使用VBA将工作表保存到具有特定名称的特定文件夹中? - How to save worksheet in a specific folder with a specific name using vba? Excel VBA-从同一文件夹中的文件导入,并带有任意名称,但末尾有特定编号 - Excel VBA - Import from a file in the same folder with an arbitrary name but a specific number at the end Excel VBA如何根据不同工作表中单元格的值删除行 - Excel VBA How to delete rows based on the value of a cell in a different worksheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM