简体   繁体   English

VBA SaveAs xlsm特定名称,带位置提示

[英]VBA SaveAs xlsm specific name with location prompt

I am trying to create a new workbook, then save it in xlsm format in a prompted location with the file name: 我正在尝试创建一个新的工作簿,然后将其以xlsm格式保存在具有文件名的提示位置

"Combined ALC Depot Reports " & Format(Date, "MM.DD.YY")

The code I have is below. 我的代码如下。 Currently it prompts you for the location, but it doesn't fill in the file name. 当前,它会提示您输入位置,但未填写文件名。

Sub NewWb()
Dim Aname As String
Dim fileToSaveAs As Variant

Aname = "Combined ALC Depot Reports " & Format(Date, "MM.DD.YY")
Workbooks.Add

ChDir "C:/temp/" 'Change to initial path

fileToSaveAs = Application.GetSaveAsFilename(InitialFileName:=Aname, FileFilter:="Excel Macro-Enabled Workbook (*.xlsm), *.xlsm")

 If fileToSaveAs <> False Then
     ActiveWorkbook.SaveAs FileName:=fileToSaveAs, FileFormat:=52
 End If

End Sub

Any help would be appreciated! 任何帮助,将不胜感激! Thanks! 谢谢!

Forget the chdir and include the path into Aname. 忘记chdir ,并将路径包括到Aname中。 the below code worked perfectly, opening in TEMP folder with a default name TEST: 下面的代码运行完美,在TEMP文件夹中使用默认名称TEST打开:

Sub NewWb()
    Dim Aname As String
    Dim fileToSaveAs As Variant

    Aname = "c:\temp\test"
    Workbooks.Add

    ChDir "C:\" '--->no effect

    fileToSaveAs = Application.GetSaveAsFilename(InitialFileName:=Aname, FileFilter:="Excel Macro-Enabled Workbook (*.xlsm), *.xlsm")

     If fileToSaveAs <> False Then
         ActiveWorkbook.SaveAs Filename:=fileToSaveAs, FileFormat:=52
     End If

End Sub

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

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