Saving Excel workbook to constant path with filename from two fields

后端 未结 2 669
猫巷女王i
猫巷女王i 2021-02-09 07:26

I tried to search and put together a code to fit my purpose.

Sub save()
ActiveWorkbook.SaveAS Filename:=\"C:\\-docs\\cmat\\Desktop\\New folder\\ck.xls\", FileFor         


        
2条回答
  •  死守一世寂寞
    2021-02-09 08:16

    try

    Sub save()
    ActiveWorkbook.SaveAS Filename:="C:\-docs\cmat\Desktop\New folder\" & Range("C5").Text & chr(32) & Range("C8").Text &".xls", FileFormat:= _
      xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
     , CreateBackup:=False
    End Sub
    

    If you want to save the workbook with the macros use the below code

    Sub save()
    ActiveWorkbook.SaveAs Filename:="C:\Users\" & Environ$("username") & _
        "\Desktop\" & Range("C5").Text & Chr(32) & Range("C8").Text & ".xlsm", FileFormat:= _
        xlOpenXMLWorkbookMacroEnabled, Password:=vbNullString, WriteResPassword:=vbNullString, _
        ReadOnlyRecommended:=False, CreateBackup:=False
    End Sub
    

    if you want to save workbook with no macros and no pop-up use this

    Sub save()
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs Filename:="C:\Users\" & Environ$("username") & _
        "\Desktop\" & Range("C5").Text & Chr(32) & Range("C8").Text & ".xls", _
        FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
        Application.DisplayAlerts = True
    End Sub
    

提交回复
热议问题