delf_28
Messages postés11Date d'inscriptionjeudi 29 mars 2007StatutMembreDernière intervention 9 mai 2007
-
4 mai 2007 à 17:17
delf_28
Messages postés11Date d'inscriptionjeudi 29 mars 2007StatutMembreDernière intervention 9 mai 2007
-
9 mai 2007 à 16:42
bonjour,
Je travaille sous excel, et je chercher à lister tous les dossiers et non les fichier car je doit parcourir certain dossier et pas d'autre.
J'ai essayer avec la fonction DIR mais cela ne fonctionne pas.
jmfmarques
Messages postés7666Date d'inscriptionsamedi 5 novembre 2005StatutMembreDernière intervention22 août 201427 4 mai 2007 à 23:17
Bon (j'ai sommeil)
Tu as dit les dossiers, hein ?
Insère donc un contrôle DirlistBox nommé Dir1 et un bouton de commande nommé Command1 et ce code
Lance, clique sur command1
Clique ensuite sur un dossier
Vois...
Et Prends là-dedans (fais le ménage) ce qui t'intéresse ...
Private Sub Command1_Click()
Dir1.Path = "d:\monoutil" 'ici ton chemin à toi, bien sur ...
For i = 1 To Dir1.ListCount
MsgBox Dir1.List(i)
Next
End Sub
Private Sub Dir1_Click()
MsgBox Dir1.List(Dir1.ListIndex)
End Sub
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201827 4 mai 2007 à 23:16
Bonjsoir,
L'exemple ci-dessous existe surement en vb6.
Option Explicit
Dim objFso, objRootFolder
Dim strRootPath, strSubFolder, strResult
strRootPath = "D:\Mes_scripts_VBFrance"
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objRootFolder = objFso.GetFolder(strRootPath)
Call SearchFolders(objRootFolder)
Msgbox strResult,,"Enumératon Sous-Répertoire(s) de " & strRootPath
Set objRootFolder = Nothing
Set objFso = Nothing
Sub SearchFolders(ArgFolder)
For Each strSubFolder In ArgFolder.SubFolders
On Error Resume Next ' permission
Call SelectFolder(strSubfolder)
Call SearchFolders(strSubfolder)
Next
End Sub
Sub SelectFolder(ArgFolder)
strResult = strResult &vbCrLf& ArgFolder
End Sub
mortalino
Messages postés6786Date d'inscriptionvendredi 16 décembre 2005StatutMembreDernière intervention21 décembre 201118 5 mai 2007 à 06:21
Salut Exploreur ;)
Merci pour mon code Hélas, WMI est gourmand en ressource. Pour ce qu'il souhaite, je lui conseille mon Snippet
Sub Cherche_Fichiers_Dans_Dossier()
Dim strMessage As String
Dim i As Long
Set fs = Application.FileSearch
With fs
.LookIn = "C:" ' *** mettre ici le dossier voulu !
.SearchSubFolders = True
.Filename = "*.exe" ' *** extension à
modifier
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "Il y a " & .FoundFiles.Count & _
" fichier(s) trouvé(s)."
For i = 1 To .FoundFiles.Count
Cells(i, 1).Value = .FoundFiles(i)
'
*** attention à la localisation. Modifie au besoin
Next i
Else
MsgBox "Il n'y a aucun fichier."
End If
End With
End Sub
~
<small>[code.aspx?ID=39466 Mortalino] ~
Colorisation automatique</small>
Bonne journée à tous
@++
<hr size="2" width="100%" />
--Mortalino--
Le mystérieux chevalier, ~Provençal, le Gaulois~
jmfmarques
Messages postés7666Date d'inscriptionsamedi 5 novembre 2005StatutMembreDernière intervention22 août 201427 5 mai 2007 à 07:28
Bonjour Mortalino,
Pas de dirlistbox en VBA ?
Bon...
On utilise alors la finction DIR
Un bouton de commande Command1 et une listbox List1
on lance, on clique sur commande1, on choisit un dossier
Private repprinc As String
Private Sub Command1_Click()
repprinc = "d:\monoutil" ' ici le dossier principal à scanner
reptrouv = Dir(repprinc, vbDirectory)
List1.Clear
Do While reptrouv <> ""
If reptrouv <> "." And reptrouv <> ".." Then
If (GetAttr(repprinc & reptrouv) And vbDirectory) = vbDirectory Then
List1.AddItem reptrouv
End If
End If
reptrouv = Dir
Loop
End Sub
Private Sub List1_Click()
MsgBox repprinc & List1.List(List1.ListIndex)
End Sub
jmfmarques
Messages postés7666Date d'inscriptionsamedi 5 novembre 2005StatutMembreDernière intervention22 août 201427 5 mai 2007 à 08:43
Re;
Je vois par ailleurs que tbbuim1 a fait ce qu'il fallait pour palier cette carence de VBA.
On trouvera ici sa source, accompagnée des OCX prêts à l'emploi dans VBA, dont le DirlistBox.OCX
delf_28
Messages postés11Date d'inscriptionjeudi 29 mars 2007StatutMembreDernière intervention 9 mai 2007 9 mai 2007 à 09:53
bonjour,
Merci a tous pour vos réponses mais jej suis toujours bloquée.
jmfmarques j'ai essayée ta méthode mais j'ai une info qui me dit : Membre de méthode ou de données introuvable en ce qui concerne .Path dans la 1ere ligne du code:
Private Sub CommandButton1_Click()
Dir1.Path = "C:\Documents and Settings\Mes documents"
For i = 1 To Dir1.ListCount
MsgBox Dir1.List(i)
Next
End Sub
cs_MPi
Messages postés3877Date d'inscriptionmardi 19 mars 2002StatutMembreDernière intervention17 août 201823 9 mai 2007 à 10:53
Pour que ce soit plus simple à écrire, copie les fichiers OCX (ainsi que les DEP, DLL, et autres bizzareries fournies) dans le répertoire System32 de Windows.
Ensuite, bouton Démarrer / Exécuter
Dans la fenêtre qui s'ouvre, tape
regsvr32 "NomDuOcx.ocx"
Tu devrais recevoir un message te disant que l'enregistrement a réussi.