Hi This is my code in VB6.0
, the problem that I have that only loads me a record of the excel spreadsheet at FlexGrid
, if I have 15 records I only load one, my question is the following:
What will be the problem that only one record of the excel spreadsheet loads me and not all?
Private Sub Excel_FlexGrid(sPath As String, FlexGrid As Object, Filas As Integer, Columnas As Integer, Optional sSheetName As String = vbNullString)
Dim i As Long
Dim n As Long
On Error GoTo error_sub
' -- Comproba si existe l archivo
If Len(Dir(sPath)) = 0 Then
MsgBox "No se ha encontrado el archivo: " & sPath, vbCritical
Exit Sub
End If
Me.MousePointer = vbHourglass
' -- crea rnueva instancia de Excel
Set obj_Excel = CreateObject("Excel.Application")
'obj_Excel.Visible = True
' -- Abrir el libro
Set obj_Workbook = obj_Excel.Workbooks.Open(sPath)
' -- referencia la Hoja, por defecto la hoja activa
If sSheetName = vbNullString Then
Set obj_Worksheet = obj_Workbook.ActiveSheet
Else
Set obj_Worksheet = obj_Workbook.Sheets(sSheetName)
End If
' -- Setear Grid
With MSFlexGrid1
' -- Especificar la cantidad de filas y columnas
'.Cols = Columnas
.Rows = Filas
' -- Recorrer las filas del FlexGrid para agregar los datos
For i = 1 To .Rows - 1
' -- Establecer la fila activa
.Row = i
' -- Recorrer las columnas del FlexGrid
For n = 0 To .Cols - 1
' -- Establecer columna activa
.Col = n
' -- Asignar a la celda del Flex el contenido de la celda del excel
.Text = obj_Worksheet.Cells(i + 1, n + 1).Value
Next
Next
End With
' -- Cerrar libro
obj_Workbook.Close
' -- Cerrar Excel
obj_Excel.Quit
' -- Descargar objetos para liberar recursos
Call Descargar
' -- Errores
Exit Sub
error_sub:
MsgBox Err.Description
Call Descargar
Me.MousePointer = vbDefault
End Sub