Propiedad FileDialog.FilterIndex (Office)
Obtiene o establece un valor Long que indica el filtro de archivo predeterminado de un cuadro de diálogo de archivo. El filtro predeterminado determina qué tipos de archivos se muestran cuando se abre el cuadro de diálogo de archivo por primera vez. Lectura y escritura.
Sintaxis
expresión. FilterIndex
expresión Variable que representa un objeto FileDialog.
Observaciones
Si intenta establecer esta propiedad en un número superior que el de filtros, se seleccionará el último filtro disponible.
Ejemplo
El ejemplo siguiente muestra un cuadro de diálogo Selector de archivos mediante el objeto FileDialog, así como cada archivo seleccionado en un cuadro de mensaje. En este ejemplo también se muestra cómo agregar un filtro de archivo nuevo y convertirlo en el filtro predeterminado.
Sub Main()
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Declare a variable to contain the path
'of each selected item. Even though the path is aString,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant
'Use a With...End With block to reference the FileDialog object.
With fd
'Add a filter that includes GIF and JPEG images and make it the second item in the list.
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 2
'Sets the initial file filter to number 2.
.FilterIndex = 2
'Use the Show method to display the File Picker dialog box and return the user's action.
'If the user presses the button...
If .Show = -1 Then
'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems
'vrtSelectedItem is aString that contains the path of each selected item.
'Use any file I/O functions that you want to work with this path.
'This example displays the path in a message box.
MsgBox "Selected item's path: " & vrtSelectedItem
Next vrtSelectedItem
'If the user presses Cancel...
Else
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
End Sub
Vea también
Soporte técnico y comentarios
¿Tiene preguntas o comentarios sobre VBA para Office o esta documentación? Vea Soporte técnico y comentarios sobre VBA para Office para obtener ayuda sobre las formas en las que puede recibir soporte técnico y enviar comentarios.
Comentarios
https://aka.ms/ContentUserFeedback.
Próximamente: A lo largo de 2024 iremos eliminando gradualmente GitHub Issues como mecanismo de comentarios sobre el contenido y lo sustituiremos por un nuevo sistema de comentarios. Para más información, vea:Enviar y ver comentarios de