【发布时间】:2025-12-05 00:20:12
【问题描述】:
Word VBA 中的“另存为”对话框有客户过滤器的方法(代码)吗?例如:“.ttt”
【问题讨论】:
-
您要显示预定义文件类型的“另存为”对话框吗?但它不会将文件转换为“.psd”,因为 word 不支持这种类型...
-
.psd 文件格式是展示自定义过滤器的示例。谢谢
标签: vba filter ms-word dialog save-as
Word VBA 中的“另存为”对话框有客户过滤器的方法(代码)吗?例如:“.ttt”
【问题讨论】:
标签: vba filter ms-word dialog save-as
我认为您可能想使用Application.FileDialog,因为它允许自定义文件过滤器。正如 KazJaw 指出的那样,您无法在 Word 中保存 Photoshop 文件,因此我认为它允许对 psd 文件进行其他操作。
下面将向您展示如何使用它(请参阅http://msdn.microsoft.com/en-us/library/aa219843%28office.11%29.aspx)。请注意,这将允许用户选择多个文件。
Sub CustomFilter()
'Declare a variable for the FileDialog object and one for the selectedItems
Dim fd As FileDialog, vSelectedItem As Variant
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'With the FileDialog
With fd
.Filters.Clear 'Clear current filters
.Filters.Add "Photoshop Files", "*.psd", 1 'Add a filter that has Photoshop Files.
If .Show = -1 Then
'Step through each String in the FileDialogSelectedItems collection.
For Each vSelectedItem In .SelectedItems
'Do whatever you want here
Next vSelectedItem
Else
'The user pressed Cancel.
End If
End With
Set fd = Nothing
End Sub
【讨论】:
.Show 的值将等于0(根据记忆,我目前不在计算机旁),然后您可以使用代码来处理它。