简体   繁体   English

Excel 另存为按钮宏

[英]Excel Save As Button Macro

I would like to create a VB "Save As" macro for Excel that would utilize the data from cell B7 , B5 and =NOW as the file name.我想为 Excel 创建一个 VB“另存为”宏,它将利用单元格B7B5=NOW中的数据作为文件名。 This new file name would then be saved to a particular directory.然后,这个新文件名将保存到特定目录。 (Ex. User clicks "Save" button. File name = (B5)ABCD_(B7)EFGH_=NOW is created and then saved to a directory of my choosing. (例如,用户单击“保存”按钮。 File name = (B5)ABCD_(B7)EFGH_=NOW已创建,然后保存到我选择的目录中。

I have found scripts that offer some of the singular options, but have had no luck finding or creating a script of my own with these options.我找到了提供一些单一选项的脚本,但没有找到或使用这些选项创建我自己的脚本。 Any help would be greatly appreciated.任何帮助将不胜感激。

You need to substitute for the invalid characters in the filename (they can't contain / or : ) with periods or something else.您需要用句点或其他内容替换文件名中的无效字符(它们不能包含/: )。

Sub DateFile()
    Dim str As String
    str = Range("B5").Value & "ABCD_" & Range("B7").Value & "EFGH" & Now()
    str = Replace(str, "/", ".")
    str = Replace(str, ":", ".")
    ActiveWorkbook.SaveAs (str)
End Sub

This can then be integrated into your push button code.然后可以将其集成到您的按钮代码中。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM