Vba 将XLSM文件另存为任意文件名、格式和目录

Vba 将XLSM文件另存为任意文件名、格式和目录,vba,excel,save-as,Vba,Excel,Save As,我正在寻找一个宏,将当前打开的XLSM文件保存为XLSM文件以外的其他文件,条件如下 我希望能够将文件保存为任何名称 我希望能够将文件保存为任何格式 我希望能够选择保存它的目录 因此,基本上我希望能够保存文件,就像不使用宏而执行普通的另存为文件一样 我已经看到了许多不同的宏,它们执行我请求的一部分,但不满足所有条件。使用FileDialog: Sub Example1() Dim intChoice As Integer Dim strPath As String 'make the fi

我正在寻找一个宏,将当前打开的XLSM文件保存为XLSM文件以外的其他文件,条件如下

  • 我希望能够将文件保存为任何名称

  • 我希望能够将文件保存为任何格式

  • 我希望能够选择保存它的目录

  • 因此,基本上我希望能够保存文件,就像不使用宏而执行普通的另存为文件一样

    我已经看到了许多不同的宏,它们执行我请求的一部分,但不满足所有条件。

    使用FileDialog:

    Sub Example1()
    Dim intChoice As Integer 
    Dim strPath As String 
    
    'make the file dialog visible to the user 
    intChoice = Application.FileDialog(msoFileDialogSaveAs).Show
    'determine what choice the user made 
    If intChoice <> 0 Then 
        'get the file path selected by the user 
        strPath = _ 
            Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1) 
        'displays the result in a message box 
    Call MsgBox(strPath, vbInformation, "Save Path")
    End If 
    End Sub 
    
    子示例1()
    选择整数
    将strPath设置为字符串
    '使文件对话框对用户可见
    intChoice=Application.FileDialog(msoFileDialogSaveAs).Show
    '确定用户所做的选择
    如果选择0,那么
    '获取用户选择的文件路径
    strPath=\u
    Application.FileDialog(msoFileDialogSaveAs)。选择editems(1)
    '在消息框中显示结果
    调用MsgBox(strPath,vbInformation,“保存路径”)
    如果结束
    端接头
    

    要使用
    SaveAs
    ,请看一看:

    的工作原理与我想要的完全一样。我只是觉得这样做需要更多的代码。非常感谢!