J'extraire des données de l'AS400 en utilisant une macro Excel. Dans l'AS400, cette colonne particulière (Ref), montre 20100729000078154 mais quand je l'ai extrait pour exceler, ce sera 2.01007E + 16. J'ai besoin de hv 20100729000078154 comme ma sortie finale. Ceci est la macro que j'ai utilisé pour extraire les informations du AS400: -Convertir au format texte Dans Excel
Sub Extract()
Dim StrSQl As String
FromA = Format(Sheet1.Range("B3"))
FromB = Format(Sheet1.Range("B4"))
FromC = Format(Sheet1.Range("B5"))
FromD = Format(Sheet1.Range("B6"))
StrSQl = "select Cno,Itno,Ref from test "
StrSQl = StrSQl & " where Cno= " & FromA & " and Itno like " & FromB & " and "
StrSQl = StrSQl & " Ref >= " & FromC & " and Ref <= " & FromD & " "
StrSQl = StrSQl & " order by Cno "
con = "Provider=IBMDA400;Data Source=xxx.xxx.xxx.xxx;User Id=yyyyy;Password=zzzzz"
Set Db = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.recordset")
Db.ConnectionString = con
Db.Open
rs.Open StrSQl, Db, 3, 3
Sheet2.Cells(1, 1).CopyFromRecordset rs
rs.Close
Set rs = Nothing
Set cn = Nothing
End Sub
Est-ce que 'Ref' est un entier ou une chaîne? – egrunin
Étant donné que 20100729000078154 n'est pas un format de date valide dans Excel, vous pouvez le formater dans votre instruction SQL (par exemple, aaaa-mm-jj hh: mm: ss). –