2012-04-24 17 views
15

¿Hay alguna manera de abrir una ventana del Explorador de Windows desde un formulario vba, vaya a un archivo específico y selecciónelo para que el nombre del archivo se coloque en un cuadro de texto?Abra Windows Explorer y seleccione un archivo

+3

Presione la tecla mágica 'F1' en VBA Excel y busque' Application.GetOpenFilename';) –

Respuesta

46

Control hacia fuera este fragmento:

Private Sub openDialog() 
    Dim fd As Office.FileDialog 

    Set fd = Application.FileDialog(msoFileDialogFilePicker) 

    With fd 

     .AllowMultiSelect = False 

     ' Set the title of the dialog box. 
     .Title = "Please select the file." 

     ' Clear out the current filters, and add our own. 
     .Filters.Clear 
     .Filters.Add "Excel 2003", "*.xls" 
     .Filters.Add "All Files", "*.*" 

     ' Show the dialog box. If the .Show method returns True, the 
     ' user picked at least one file. If the .Show method returns 
     ' False, the user clicked Cancel. 
     If .Show = True Then 
     txtFileName = .SelectedItems(1) 'replace txtFileName with your textbox 

     End If 
    End With 
End Sub 

creo que esto es lo que está pidiendo.

+13

Usted es un ser humano hermoso. – Quintis555

Cuestiones relacionadas