【发布时间】:2015-11-19 11:44:19
【问题描述】:
我正在寻找一个宏来将当前打开的 XLSM 文件另存为具有以下条件的 XLSM 文件。
我希望能够将文件保存为任何名称。
我希望能够将文件保存为任何格式。
我希望能够选择保存的目录。
所以基本上我希望能够保存文件,就像我在不使用宏的情况下执行普通的另存为文件一样。
我已经看到了许多不同的宏,它们可以满足我的部分请求,但在所有条件下都没有。
【问题讨论】:
我正在寻找一个宏来将当前打开的 XLSM 文件另存为具有以下条件的 XLSM 文件。
我希望能够将文件保存为任何名称。
我希望能够将文件保存为任何格式。
我希望能够选择保存的目录。
所以基本上我希望能够保存文件,就像我在不使用宏的情况下执行普通的另存为文件一样。
我已经看到了许多不同的宏,它们可以满足我的部分请求,但在所有条件下都没有。
【问题讨论】:
使用文件对话框:
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
要使用SaveAs,请查看:http://www.rondebruin.nl/win/s5/win001.htm 和https://msdn.microsoft.com/fr-fr/library/office/ff841185.aspx
【讨论】: