Is there a way (code) for "Save As" dialog in Word VBA with customer filters? For example: ".ttt"

有帮助吗?

解决方案

I think you probably want to use the Application.FileDialog as this allows custom file filters. As KazJaw points out you can't save a Photoshop file in Word so I assume its to allow some other manipulation of a psd file.

The following shows you how to use it (see http://msdn.microsoft.com/en-us/library/aa219843%28office.11%29.aspx). Note this will allow the user to select multiple files though.

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top