我想在宏的顶部键入一个“文件名”,并在宏中使用此“名称”。(我做了一些Access数据库的工作,所以我在这里使用的是JavaScript代码。
// current macro begin
Sub TR_Weight_031023()
'
' TR_Weight_tracker_SAVE_111422 Macro
Application.DisplayAlerts = False
ChDir "D:\Dropbox\G_emiguy_052921\__Twix and Rolo"
ActiveWorkbook.SaveAs Filename:= _
"D:\Dropbox\G_emiguy_052921\__Twix and Rolo\TR - weight after 031023.xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\Dropbox\G_emiguy_052921\__Twix and Rolo\TR - weight after 031023.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
ActiveWorkbook.SaveAs Filename:= _
"D:\Dropbox\G_emiguy_052921\__Twix and Rolo\TR - weight after 031023.xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Range("O5:P6").Select
Application.DisplayAlerts = True
End Sub
//current macro end
我的思维过程
1.定义一个文本字符串(对吗?)作为宏顶部的“文件名”。目前的“文件名”是“TR - weight after 031023”--但是--我在宏中输入了这个。
1.在“file name”字符串中键入一个新名称(或其他类型?text??),并使用此新名称代替当前的“TR -031023后的重量”
这样做将允许我选择任何名称(例如,“TR - weight sent to Jim”),文件将是新名称。如果我把这个宏代码/宏变长,我只需要改变“文件名”的值。
我设想
** begin NEW macro with attempt to change
Sub TR_new_weight()
Dim file_name as string
file_name = "TR_new_file_name"
Application.DisplayAlerts = False
ChDir "D:\Dropbox\G_emiguy_052921\__Twix and Rolo"
ActiveWorkbook.SaveAs Filename:= _
"D:\Dropbox\G_emiguy_052921\__Twix and Rolo\"&'TR_new_file_name'&".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\Dropbox\G_emiguy_052921\__Twix and Rolo\"&'TR_new_file_name'&".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
ActiveWorkbook.SaveAs Filename:= _
"D:\Dropbox\G_emiguy_052921\__Twix and Rolo\"&'TR_new_file_name'&".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Range("O5:P6").Select
Application.DisplayAlerts = True
End Sub
** end NEW macro with attempt to change
1条答案
按热度按时间plicqrtu1#
使用输入框输入新名称