vba 使用VBA在excel 2010中每次使用不同的名称保存文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21897456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:03:11  来源:igfitidea点击:

Using VBA to save a file in excel 2010 with a different name each time

excelvbaexcel-vbaexcel-2010save-as

提问by Bolo

I have a spreadsheet that I'm using as a template to get user input. When you press the submit button on the spreadsheet, it sends the data to a different workbook that stores all the previous entries and then clears the template. Is there a way to save the template as a different file when you push the button? I know about .Saveas(), but I want a file name that's based off what was typed in cell A2 and B2?

我有一个电子表格,用作模板来获取用户输入。当您按下电子表格上的提交按钮时,它会将数据发送到存储所有先前条目的不同工作簿,然后清除模板。当您按下按钮时,有没有办法将模板另存为不同的文件?我知道 .Saveas(),但我想要一个基于单元格 A2 和 B2 中键入的内容的文件名?

回答by Jacob Lambert

I do this on a daily basis saving the file as the previous days date. I modified what I use for what you are wanting:

我每天都这样做,将文件保存为前几天的日期。我修改了我用于您想要的内容:

dim name as string

name = Cells(1,2).Value & Cells(2,2).Value

ActiveWorkbook.SaveAs() Filename:=name