[英]Macro to save Excel sheet with file name and path from cell values
I'm trying to create a macro button that will save the active sheet as a pdf, go to a specific folder(based on cell value), and have a file name based on cell value.我正在尝试创建一个宏按钮,它将活动工作表另存为 pdf、go 到特定文件夹(基于单元格值),并具有基于单元格值的文件名。 What would be the VBA code to save a the active excel sheet based on values in a cell?
基于单元格中的值保存活动 excel 工作表的 VBA 代码是什么?
Example:例子:
(First part of Path name) C:\User\Documents\ (路径名称的第一部分)C:\User\Documents\
The final part of the path will be the folder name which is in cell B2.路径的最后一部分将是单元格 B2 中的文件夹名称。
The file name I need to auto create as "Value of B1 + XXXXX(static text) + Value of D2"我需要自动创建的文件名为“B1 的值 + XXXXX(静态文本)+ D2 的值”
Example Output示例 Output
Save to: C:\User\Documents*Folder Name from B1*保存到:C:\User\Documents*B1 中的文件夹名称*
File Name: Text from B1 + "Settlement WE" + Value from D2文件名:来自 B1 的文本+ “结算 WE” +来自 D2 的值
Please help.请帮忙。
To create your file name:创建文件名:
Dim vn as String, fn as String
vn = "some string"
fn = Range("B1") & vn & Range("D2")
fn
would be your final output (unclear if D2 includes file extension or not) fn
将是您的最终 output (不清楚 D2 是否包含文件扩展名)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.