简体   繁体   English

我将如何编写 VBA 代码以将文件名保存为单元格值的 Excel 工作簿?

[英]How would I write VBA code to save an excel workbook with the filename as a cell value?

I have a workbook that will change weekly and I wanted to write a script that would save the workbook in a set location and change the name to what ever the start date of the week was.我有一个每周都会更改的工作簿,我想编写一个脚本,将工作簿保存在设定位置并将名称更改为一周的开始日期。

Any help would be greatly appreciated and if I am not being clear, I shall try and explain it better.任何帮助将不胜感激,如果我不清楚,我会尝试更好地解释它。

Thanks谢谢

You can do this using the Workbook.SaveAs -method .您可以使用Workbook.SaveAs -method执行此操作。 The page I linked to explain what the different arguments you pass to the function do, the most pertinent one for you is the first one, Filename , which you can set to be equal to just about any string (such as one retrieved from a cell).我链接的页面解释了您传递给函数的不同参数的作用,对您来说最相关的是第一个Filename ,您可以将其设置为几乎等于任何字符串(例如从单元格中检索的字符串) )。 You can also (optionally) include a filepath preceding the filename, to determine where the file is saved, otherwise it is saved to the current folder.您还可以(可选)在文件名之前包含文件路径,以确定文件的保存位置,否则将保存到当前文件夹。

Workbook.SaveAs(FileName, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodepage, TextVisualLayout, Local)

You can assign the path and the file name to FileName as String您可以将路径和文件名分配给FileName作为字符串

http://www.rondebruin.nl/win/s5/win001.htm http://www.rondebruin.nl/win/s5/win001.htm

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 VBA 复制用 VBA 打开的 Excel 工作簿的文件名,并在当前工作簿的另存为函数中使用它? - How to use VBA to copy a filename of an Excel workbook opened with VBA and use it in a save-as function for current workbook? 如何在excel vba中检查其他工作簿的单元格值是否为空 - How to check the cell value of other workbook is empty or not in excel vba VBA另存为PDF,文件名为单元格值 - VBA Save as PDF with Filename as Cell Value 如何使用VBA中的单元格名称另存为工作簿 - How to save as workbook with cell name in vba 将Excel VBA代码保存为特定文件名并关闭活动工作簿 - Excel VBA code to SaveAs a specific filename and close the active workbook Excel 2010 VBA:使用单元格中的值保存文件以确定路径和文件名 - Excel 2010 VBA: Save file using value from cell to determine path and filename 协助 Excel VBA 参考单元格将工作表移动到新工作簿并保存 - Assistance with Excel VBA Reference Cell to Move Sheet to new workbook and save (VBA 到 VB.NET 代码修改)使用 VB.NET 将特定单元格的值写入工作簿 - (VBA to VB.NET code modification) Write value to specific cell to Workbook using VB.NET 如何使用VBA自动使用来自单独的excel工作簿的数据透视表的数据填充excel工作表? - How would I use VBA to automatically populate an excel worksheet with data from the pivot table of a separate excel workbook? 使用单元格文本作为文件名在当前目录中将Excel VBA另存为 - Excel VBA Save As in current directory using cell text as filename
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM