Hola, encontramos la solución a lo que necesitas, desplázate y la obtendrás aquí.
Ejemplo: excel vba cargar csv
'VBA function to open a CSV file in memory and parse it to a 2D'array without ever touching a worksheet:Function ArrayFromCSV(sFile$)Dim c&, i&, j&, p&, d$, s$, rows&, cols&, a, r, v
Const Q ="""", QQ = Q & Q
Const ENQ =""'Chr(5)Const ESC =""'Chr(27)Const COM =","
d = OpenTextFile$(sFile)If LenB(d)Then
r = Split(Trim(d), vbCrLf)
rows = UBound(r)+1
cols = UBound(Split(r(0),","))+1ReDim v(1To rows,1To cols)For i =1To rows
s = r(i -1)If LenB(s)ThenIf InStrB(s, QQ)Then s = Replace(s, QQ, ENQ)For p =1To Len(s)SelectCase Mid(s, p,1)Case Q: c = c +1Case COM:If c Mod2Then Mid(s, p,1)= ESC
EndSelectNextIf InStrB(s, Q)Then s = Replace(s, Q,"")
a = Split(s, COM)For j =1To cols
s = a(j -1)If InStrB(s, ESC)Then s = Replace(s, ESC, COM)If InStrB(s, ENQ)Then s = Replace(s, ENQ, Q)
v(i, j)= s
NextEndIfNext
ArrayFromCSV = v
EndIfEndFunctionFunction OpenTextFile$(f)With CreateObject("ADODB.Stream").Charset ="utf-8".Open
.LoadFromFile f
OpenTextFile =.ReadText
.Close
EndWithEndFunction
Valoraciones y reseñas
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)