Exportar tabla excel desde vb6
Publicado por Victor (1 intervención) el 08/08/2007 08:53:27
Wenas he de exportar a una tabla de Excel una tabla desde VISUAL BASIC 6 y me da un error de "ERROR DE EJECUCION EL SUBINDICE ESTA FUERA DEL INTERVALO" a ver si alguien me podria decir como se soluciona.
Gracias
Private Sub SSCommand2_Click()
Dim iRowIndex As Integer, avRows As Variant
Dim iFieldCount As Integer, objExcel As Object, objTemp As Object
Dim iColIndex As Integer, iRecordCount As Integer
'elegir ruta al archivo Access
DataExcel.DatabaseName = "C:\Projectes\Seguridad\SinTdb60\talleres.mdb"
'consulta SQL
DataExcel.RecordSource = "SELECT codigo,nombre,domicilio,poblacion,provincia,telefono,email FROM tcliente"
'Actualizar
DataExcel.Refresh
With DataExcel.Recordset
.MoveFirst
avRows = .GetRows()
iRecordCount = UBound(avRows, 2) + 1
iFieldCount = UBound(avRows, 1) + 1
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add
Set objTemp = objExcel
objExcel.Visible = True
If Val(objExcel.Application.Version) >= 8 Then
Set objExcel = objExcel.ActiveSheet
End If
iRowIndex = 1
For iColIndex = 1 To iFieldCount
With objExcel.Cells(iRowIndex, iColIndex)
.Value = DataExcel.Recordset.Fields(iColIndex - 1).Name
.Range(.Cells(1, 1), .Cells(1, 5)).ColumnWidth = 20
With .Font
.Name = "Verdana"
.Bold = True
.size = 11
End With
End With
Next iColIndex
End With
With objExcel
For iRowIndex = 2 To DataExcel.Recordset.RecordCount + 1
For iColIndex = 1 To iFieldCount
'EN LA LINEA DE ABAJO ES DONDE ME DA EL ERROR
.Cells(iRowIndex, iColIndex) = avRows(iColIndex - 1, iRowIndex - 2)
Next iColIndex
Next iRowIndex
.Cells(1, 1).CurrentRegion.EntireColumn.AutoFit
End With
Set objTemp = Nothing
Set objExcel = Nothing
End Sub
Gracias
Private Sub SSCommand2_Click()
Dim iRowIndex As Integer, avRows As Variant
Dim iFieldCount As Integer, objExcel As Object, objTemp As Object
Dim iColIndex As Integer, iRecordCount As Integer
'elegir ruta al archivo Access
DataExcel.DatabaseName = "C:\Projectes\Seguridad\SinTdb60\talleres.mdb"
'consulta SQL
DataExcel.RecordSource = "SELECT codigo,nombre,domicilio,poblacion,provincia,telefono,email FROM tcliente"
'Actualizar
DataExcel.Refresh
With DataExcel.Recordset
.MoveFirst
avRows = .GetRows()
iRecordCount = UBound(avRows, 2) + 1
iFieldCount = UBound(avRows, 1) + 1
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add
Set objTemp = objExcel
objExcel.Visible = True
If Val(objExcel.Application.Version) >= 8 Then
Set objExcel = objExcel.ActiveSheet
End If
iRowIndex = 1
For iColIndex = 1 To iFieldCount
With objExcel.Cells(iRowIndex, iColIndex)
.Value = DataExcel.Recordset.Fields(iColIndex - 1).Name
.Range(.Cells(1, 1), .Cells(1, 5)).ColumnWidth = 20
With .Font
.Name = "Verdana"
.Bold = True
.size = 11
End With
End With
Next iColIndex
End With
With objExcel
For iRowIndex = 2 To DataExcel.Recordset.RecordCount + 1
For iColIndex = 1 To iFieldCount
'EN LA LINEA DE ABAJO ES DONDE ME DA EL ERROR
.Cells(iRowIndex, iColIndex) = avRows(iColIndex - 1, iRowIndex - 2)
Next iColIndex
Next iRowIndex
.Cells(1, 1).CurrentRegion.EntireColumn.AutoFit
End With
Set objTemp = Nothing
Set objExcel = Nothing
End Sub
Valora esta pregunta


0