Bonjour,
Je n'arrive tout simplement pas à faire fonctionner ce code. Quelqu'un a une idée de ce qui pourrait bien être la cause?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Public Sub TestNetShareName()
 
    Dim NetworkObject As Object
    Dim FSO As Object
    Dim Directory As Object
    Dim Filename As Object
    Dim ServerShare As String
    Dim UserName As String
    Dim Password As String
 
    ServerShare = "\\corp-server\HostingFolder"
    UserName = "mydomain\myuser"
    Password = "freddie123"
 
    Set NetworkObject = CreateObject("WScript.Network")
    Set FSO = CreateObject("Scripting.FileSystemObject")
 
    NetworkObject.MapNetworkDrive "", ServerShare, False, UserName, Password
 
    Set Directory = FSO.GetFolder(ServerShare)
    For Each Filename In Directory.Files
        Debug.Print Filename.Name
    Next
 
    Set Filename = Nothing
    Set Directory = Nothing
    Set FSO = Nothing
 
    NetworkObject.RemoveNetworkDrive ServerShare, True, False
 
    Set NetworkObject = Nothing
 
End Sub