Bonjour,
j'intégre un fichier externe (AS400) dans une feuille excel via ADO par le code suivant mais je souhaite aussi récupérer les noms des zones en ligne 1, ce que je ne parviens pas à faire.

Je suppose qu'il y a un parametre ou une méthode pour cela.

Pouvez-vous m'aider. merci.
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
34
35
36
37
38
39
40
41
42
43
 
Function GetConnexion() As ADODB.Connection
    On Error GoTo ErrorHandler
 
    Dim cn          As New ADODB.Connection
    Dim rs          As New ADODB.Recordset
    Dim sConn       As String
    Dim SqlString   As String
    Dim Filename    As String
    Dim Ws          As String
    Dim Rg          As String
 
 
    sConn = "provider=IBMDA400.DataSource1;Data source=xx.xxx.xxx.xxx;USER ID=userid;PASSWORD=password"
    Filename = "library.Filename"
    Ws = "Sheet1"
    Rg = "A1"
 
    cn.ConnectionString = sConn
    cn.Open
    SqlString = "SELECT * FROM " & Filename & ""
 
    rs.Open SqlString, cn
 
    Worksheets(Ws).Range(Rg).CopyFromRecordset rs
    Set GetConnexion = cn
    rs.close
    cn.close
    Set cn = Nothing
    Set rs = nothing
 
    Exit Function
ErrorHandler:
    ' clean up
    If Not cn Is Nothing Then
        If cn.State = adStateOpen Then cn.Close
    End If
    Set cn = Nothing
    If Err <> 0 Then
      MsgBox Err.Source & "-->" & Err.Description, , "Error"
    End If
 
End Function