Excel 宏到 'Save As' 在设置的驱动器位置作为 .xlsm

Excel Macro to 'Save As' in a set drive location as a .xlsm

我正在尝试编写一个宏来将 excel 文件保存在定义的位置,使用单元格中的值作为 .xlsm 格式的标题,它似乎有效但实际上并没有保存文件?我不确定我做错了什么?这是宏:

Sub Savefileas()
ThisFile = Range("B4").Value
Dim varResult As Variant

varResult = Application.GetSaveAsFilename(FileFilter:= _
"Macro Enabled Workbook" & "(*.xlsm), *xlsm", Title:=Range("B4").Value &".xlsm", _
InitialFileName:="C:\Work\" & ThisFile & ".xlsm")

End Sub

感谢您的支持

试一试。还添加了错误捕获。

Sub Savefileas()
    Dim ThisFile As String
    Dim varResult As Variant
    ThisFile = Range("B4").Value
    varResult = Application.GetSaveAsFilename(FileFilter:= _
    "Macro Enabled Workbook" & "(*.xlsm), *xlsm", Title:=ThisFile & ".xlsm", InitialFileName:="C:\My Documents\" & ThisFile & ".xlsm")
    With ActiveWorkbook
        On Error GoTo message
        .SaveAs varResult & ".xlsm", FileFormat:=52
        Exit Sub
        message:
        MsgBox "There is an error"
    End With
End Sub