Recherche avec la recherche Windows

  • Initiateur de la discussion Initiateur de la discussion ptibaz
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

ptibaz

XLDnaute Junior
Bonjour à tous!

Je souhaite créer une macro qui ouvre la recherche Windows dans le dossier où se trouve mon classeur (ActiveWorkbook.Path) et rechercher les fichiers *.pdf (par exemple).

Est-ce possible de piloter la recherche windows dans excel ?

Merci d'avance pour vos pistes...
 
Re : Recherche avec la recherche Windows

Bonjour,

Je souhaite créer une macro qui ouvre la recherche Windows dans le dossier où se trouve mon classeur (ActiveWorkbook.Path) et rechercher les fichiers *.pdf (par exemple).
la fonction "DIR" native de vba devrait suffire non ?? F1 dans l'éditeur vba te donnera un exemple...

bon après midi
@+
 
Re : Recherche avec la recherche Windows

Re,

un exemple ci-dessous, liste tous les fichiers xls du réertoire où se ttrouve le classeur dans lequel est exécuté le code :
Code:
Sub test()
Dim r As String, f As String, i As Long
r = ThisWorkbook.Path & "\"
f = Dir(r & "*.xls")
Do While f <> ""
    i = i + 1
    Cells(i, 1) = f
    f = Dir
Loop
End Sub
 
Re : Recherche avec la recherche Windows

Bonjour le fil 🙂,
En espérant que ça fonctionnait déjà sous 2002 🙄 :
Code:
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
        'Set the initial path to the C:\Temp\ drive.
        .InitialFileName = "C:\Temp\"
        'Add a filter that includes PDF files and make it the first item in the list.
        .Filters.Add "Acrobat PDF", "*.pdf", 1
        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the button.
    If .Show = -1 Then
            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems
                'vrtSelectedItem is a string that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example displays the path in a message box.
                MsgBox "The path is: " & vrtSelectedItem
            Next vrtSelectedItem
        'The user pressed Cancel.
    Else
        End If
    End With
    'Set the object variable to nothing.
    Set fd = Nothing
End Sub
Bonne journée 😎
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
19
Affichages
696
  • Question Question
Microsoft 365 Lien vers pdf
Réponses
3
Affichages
167
Retour