Hola estoy cargando una hoja Excel a una grilla de VB6 y creo que el método que estoy empleando es lento, creo recordar que hay otros métodos mas rápidos, yo utilizo dos for X, y for Y recorriendo celda por celda y obtengo su valor (esto en 790 filas con 21 columnas me esta demorando 1 minuto), pero creo que había una forma de obtener un array de las celda lo cual es mas rápido
mi código actual
Private Sub Form_Load()
Dim LastRow As Long
Dim i As Integer
Dim XL As Object, xlSpread As Object
Const xlLastCell = 11
Dim Row As Long, Col As Long
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open FileName:=App.Path & "\L1.xlsx", ReadOnly:=False
Set xlSpread = XL.Application
LastRow = xlSpread.ActiveCell.SpecialCells(xlLastCell).Row
With ucGridPlus1
.Redraw = False
.ColsCount = 21
.RowsCount = LastRow - 6 + 1
'Encabesados
For i = 0 To 20
.ColumText(i) = xlSpread.Cells(5, i + 1).Value
Next
i = 0
'Celdas/Tabla
For Row = 6 To LastRow
For Col = 0 To 20
.CellValue(i, Col) = xlSpread.Cells(Row, Col + 1).Value
Next
i = i + 1
'Debug.Print Row
Next
.Redraw = True
End With
XL.Application.DisplayAlerts = False
XL.ActiveWorkbook.Close False 'Dont save changes (if any)
XL.Quit
Set XL = Nothing
End Sub
Featured Replies
Archivado
Este tema está ahora archivado y está cerrado a más respuestas.
Hola estoy cargando una hoja Excel a una grilla de VB6 y creo que el método que estoy empleando es lento, creo recordar que hay otros métodos mas rápidos, yo utilizo dos for X, y for Y recorriendo celda por celda y obtengo su valor (esto en 790 filas con 21 columnas me esta demorando 1 minuto), pero creo que había una forma de obtener un array de las celda lo cual es mas rápido
mi código actual
Private Sub Form_Load() Dim LastRow As Long Dim i As Integer Dim XL As Object, xlSpread As Object Const xlLastCell = 11 Dim Row As Long, Col As Long Set XL = CreateObject("Excel.Application") XL.Workbooks.Open FileName:=App.Path & "\L1.xlsx", ReadOnly:=False Set xlSpread = XL.Application LastRow = xlSpread.ActiveCell.SpecialCells(xlLastCell).Row With ucGridPlus1 .Redraw = False .ColsCount = 21 .RowsCount = LastRow - 6 + 1 'Encabesados For i = 0 To 20 .ColumText(i) = xlSpread.Cells(5, i + 1).Value Next i = 0 'Celdas/Tabla For Row = 6 To LastRow For Col = 0 To 20 .CellValue(i, Col) = xlSpread.Cells(Row, Col + 1).Value Next i = i + 1 'Debug.Print Row Next .Redraw = True End With XL.Application.DisplayAlerts = False XL.ActiveWorkbook.Close False 'Dont save changes (if any) XL.Quit Set XL = Nothing End Sub