简体   繁体   中英

Word VBA Save As Dialog with custom filter?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM