简体   繁体   English

用于保存 Excel 工作表的宏,其中包含来自单元格值的文件名和路径

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

相关问题 VBA宏使用另一个工作簿中单元格的路径保存Excel文件 - VBA macro to save excel file using path from cell in another workbook Excel中的VB宏可使用单元格中的名称将活动文档保存为PDF - VB macro in excel to save an active doc to PDF with name from a Cell 从单元格获取文件名并提示保存文件位置的宏 - Macro for getting the file name from the cell and prompt the location to save the file Excel宏或函数:如果单元格不为空,则使用循环值(来自另一张纸)填充单元格区域(A列) - Excel Macro or Function: Populate a cell range (Column A) with a looped values (from another sheet) if cell is not blank 使用宏从单元格将Excel工作表保存为CSV文件格式的CSV文件 - Saving excel worksheet to CSV with file name from a cell using a macro Excel宏可将数据从一个表移动到另一列,并基于列名和单元格内容 - Excel macro to move data from one sheet to another based column name and cell content 打开另存为窗口,并从单元格填充文件名和文件路径 - Open save as window and populate file name and file path from cell 在Excel宏的工作表中指定单元格 - specifying a cell in a sheet in an Excel macro VBA Excel宏使用VLOOKUP从不同的工作表中减去单元格 - VBA Excel Macro to subtract cell from different sheet using VLOOKUP Excel - 使用文件名(存储在单元格中)来引用该文件中的值 - Excel - using the name of the file (stored in a cell) to reference values from that file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM