|
Muchísimas gracias Mihura.
Precisamente lo que hago es importar los datos a una tabla temporal, y luego a la definitiva con sus filtros correspondiente.
Lo que hace el programa es abrir el excel, modifica las fechas que hay en él, pasándola a número (la tabla temporal las recibe como número), y mediante la instrucción que he puesto, la incluyen en la tabla temporal, y se cierra el excel. Luego con SELECT e INSERT INTO, va depurando e incluyendo en la tabla definitiva. Y funciona de maravilla, pero aún así, me crea una tabla con los errores de importación. Incluso he comprobado los errores, por si me faltan en la definitiva, pero no faltan o si faltan son datos que no necesito.
Te pongo parte del código en el que se abre excel, se pasa a la tabla temporal.
Set xLsBook = Workbooks.Open(RutA) Set xLsApp = xLsBook.Parent 'xLsApp.Visible = True HojaName = xLsBook.ActiveSheet.Name
Set CnX = CurrentProject.Connection a = 0 b = xLsBook.Worksheets(HojaName).Range("a" & Rows.Count).End(xlUp).Row xLsBook.Worksheets(HojaName).Range("B1") = "NIFEmisor" xLsBook.Worksheets(HojaName).Range("C1") = "NDocumento" xLsBook.Worksheets(HojaName).Range("D1") = "FechaFactura" xLsBook.Worksheets(HojaName).Range("E1") = "FechaVencimiento" xLsBook.Worksheets(HojaName).Range("H1") = "NIFReceptor" xLsBook.Worksheets(HojaName).Range("I1") = "EstadoDocumento" xLsBook.Worksheets(HojaName).Range("J1") = "FechaEstado" xLsBook.Worksheets(HojaName).Range("K1") = "Codigoservicioext" xLsBook.Worksheets(HojaName).Range("L1") = "Fechaemision" xLsBook.Worksheets(HojaName).Range("M1") = "Fecharegistro" xLsBook.Worksheets(HojaName).Range("N1") = "NRegistro" xLsBook.Worksheets(HojaName).Range("O1") = "IdExterno" xLsBook.Worksheets(HojaName).Range("P1") = "Documentosadjuntos" xLsBook.Worksheets(HojaName).Range("Q1") = "MotivoRechazo" xLsBook.Worksheets(HojaName).Range("d:d").Select Selection.NumberFormat = "0" xLsBook.Worksheets(HojaName).Range("e:e").Select Selection.NumberFormat = "0" For ttr = 2 To b xLsBook.Worksheets(HojaName).Range("j" & ttr) = Int(xLsBook.Worksheets(HojaName).Range("j" & ttr)) PaR = ttr Ref = (PaR * 100) / b ProgressBar4 = Ref Next ttr EtqProgress.Caption = "Actualizando rechazos" ProgressBar4 = 0 xLsBook.Worksheets(HojaName).Range("j:j").Select Selection.NumberFormat = "0" xLsBook.Worksheets(HojaName).Range("l:m").Select Selection.NumberFormat = "0" xLsBook.Close Set xLsApp = Nothing DoCmd.TransferSpreadsheet acImport, , "RechazosTemp", RutA, True, HojaName & "!A1:Q" & b EtqProgress.Visible = True EtqProgress.Caption = "Actualizando rechazos" ProgressBar4.Visible = True ProgressBar4 = 0 EtqProgress.Visible = True
En cuanto acaba de hacer el "Docmd....", se crea una tabla nueva en access con el nombre de la hoja excel y al final el litarl "ErroresDeImportacion..."
El Access funciona bien, pero de vez en cuando tengo que eliminar las tablas que me crea.
A ver que te parece.
Saludos y gracias por anticipado.
------------- Si te caes siete veces, levántate ocho (Proverbio chino)
|