Problemas con una Matriz
Publicado por barca1010 (132 intervenciones) el 06/08/2007 10:10:07
Espero que me puedan ayudar, tengo este codigo que utilizo para leer un archivo de excel y luego grabo la informacion en una base de datos, el problema lo tengo al pulsar sobre el boton de importar mas de una vez, en la segunda me aparece el error "Error en el método 'Cells' del objeto '_Global'"
Este es mas o menos el codigo que utilizo, le he quitado la rutina de guardado para que no sea tan largo.
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim xlLibro As Excel.Workbook
Dim xlHoja As Excel.Worksheet
Dim varMatriz() As Variant
Dim MaxRow As Long
Dim MaxCol As Long
Set xlApp = New Excel.Application
Set xlLibro = xlApp.Workbooks.Open("c:\Datos Enero 06.xls")
Set xlHoja = xlApp.Worksheets("Cta Ene06")
MaxRow = xlHoja.Cells.SpecialCells(xlLastCell).Row
MaxCol = xlHoja.Cells.SpecialCells(xlLastCell).Column
varMatriz = xlHoja.Range(Cells(1, 1), Cells(MaxRow, MaxCol))
xlLibro.Close
xlApp.Quit
Set xlHoja = Nothing
Set xlLibro = Nothing
Set xlApp = Nothing
End Sub
Este es mas o menos el codigo que utilizo, le he quitado la rutina de guardado para que no sea tan largo.
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim xlLibro As Excel.Workbook
Dim xlHoja As Excel.Worksheet
Dim varMatriz() As Variant
Dim MaxRow As Long
Dim MaxCol As Long
Set xlApp = New Excel.Application
Set xlLibro = xlApp.Workbooks.Open("c:\Datos Enero 06.xls")
Set xlHoja = xlApp.Worksheets("Cta Ene06")
MaxRow = xlHoja.Cells.SpecialCells(xlLastCell).Row
MaxCol = xlHoja.Cells.SpecialCells(xlLastCell).Column
varMatriz = xlHoja.Range(Cells(1, 1), Cells(MaxRow, MaxCol))
xlLibro.Close
xlApp.Quit
Set xlHoja = Nothing
Set xlLibro = Nothing
Set xlApp = Nothing
End Sub
Valora esta pregunta


0