Usb sur vba
Résolu
rah-mani
Messages postés
55
Statut
Membre
-
tompols Messages postés 1273 Date d'inscription Statut Contributeur Dernière intervention -
tompols Messages postés 1273 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour,
j'ai u programmes de excel mes pour Enregistrer dans mon usb mes l’en blasement ça change toujours dans
E:\ APRIS F:\
COMMENT FAIRE POUR RECONNER USB DANE QUEL EMPLACEMENT
MON CODE
Private Sub CommandButton2_Click()
On Error Resume Next
Dim G As Long
clo = FreeFile
Open "E:\RAHMANI.TEXT" For Append Lock Write As #clo
Print #clo, Cells(1, 6), Cells(2, 4), CommandButton1.Caption
For G = 5 To 200
If Cells(G, 2).lien > 4 Then
Print #clo, Cells(G, 1), Cells(G, 2), Cells(G, 3), Cells(G, 4), Cells(G, 5), Cells(G, 6), Cells(G, 7), Cells(G, 8)
End If
Next G
Close #clo
End Sub
j'ai u programmes de excel mes pour Enregistrer dans mon usb mes l’en blasement ça change toujours dans
E:\ APRIS F:\
COMMENT FAIRE POUR RECONNER USB DANE QUEL EMPLACEMENT
MON CODE
Private Sub CommandButton2_Click()
On Error Resume Next
Dim G As Long
clo = FreeFile
Open "E:\RAHMANI.TEXT" For Append Lock Write As #clo
Print #clo, Cells(1, 6), Cells(2, 4), CommandButton1.Caption
For G = 5 To 200
If Cells(G, 2).lien > 4 Then
Print #clo, Cells(G, 1), Cells(G, 2), Cells(G, 3), Cells(G, 4), Cells(G, 5), Cells(G, 6), Cells(G, 7), Cells(G, 8)
End If
Next G
Close #clo
End Sub
Configuration: Windows XP Internet Explorer 6.0
5 réponses
-
re,
Alors ton code donnerait ceci :Private Sub CommandButton2_Click() On Error Resume Next Dim G As Long clo = FreeFile strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery _ ("Select * from Win32_LogicalDisk") For Each objDisk in colDisks if objDisk.VolumeName = "lenomdetaclé" then fichier = objDisk.caption & "\RAHMANI.TEXT" end if next Open fichier For Append Lock Write As #clo Print #clo, Cells(1, 6), Cells(2, 4), CommandButton1.Caption For G = 5 To 200 If Cells(G, 2).lien > 4 Then Print #clo, Cells(G, 1), Cells(G, 2), Cells(G, 3), Cells(G, 4), Cells(G, 5), Cells(G, 6), Cells(G, 7), Cells(G, 8) End If Next G Close #clo End Sub
Remplacer "lenomdetaclé" par "USB DANE" ou le nom qui apparait ds l'explorateur windows... -
Bonjour
Tu peux utiliser WMI pour ça :strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery _ ("Select * from Win32_LogicalDisk") For Each objDisk in colDisks if objDisk.VolumeName = lenomdetaclé then fichier = objDisk.caption & "\RAHMANI.TEXT" ton code à mettre ici end if next
Voilà, là je l'ai fait en basant sur le nom de ta clé usb mais tu pourrais aussi utiliser le numéro de série de la clé etc....
https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-logicaldisk?redirectedfrom=MSDN -
-
-
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question -
de rien ;), oublie pas de mettre en "résolu" si c'est le cas...
bonne journée