Saltar al contenido

Macro que genere archivos xls de xml


FERMUGUZ

Recommended Posts

publicado

Buenos dias estimados.

Espero me puedan apoyar pues ya tengo 2 dias trabajando con macros para archvos xml, ya he generado las siguientes macros .

La primera convierte los archivos XML en XLS, la segunda abre los archivos ya generados y la ultima junta en una sola hoja toda la informacion de cada archivo ya convertido en XLS.

MI PROBLEMA RADICA QUE CUANDO ME GENERA LOS ARCHIVOS XLS ME MANDA VENTANA DE GUARDAR COMO EL PROBLEMA ES QUE MANEJO APROX DE ENTRE 1800 A 6000 FACTURAS POR DIA.

Cuando corro la macro me pregunta Guardar como y los nombres de los archivos que se generean de los XML toman por defaul el nompre del archivo original del XML ejemplo si mi archivo se llama D0E1AD2C-146C-4F98-B60C-8F0FD02D5EF3 el archivo que se genera de excel toma el sig nombre Copy of D0E1AD2C-146C-4F98-B60C-8F0FD02D5EF3 pero como reitero me manda la ventana de Guardar como.

No quiero que me este preguntando Guardar Como por cada XML que es convertido a XML.

Sub abrir_archivos()

Application.ScreenUpdating = False

ruta = ThisWorkbook.Path

ChDir ("C:\Users\FERNANDO-MUÑOZ\Desktop\Del 10 al 16")

archi = Dir("*.xml*")

On Error Resume Next

If archi = "" Then

MsgBox ("No hay archivos xml en la carpeta " & "(" & ruta & ")" & " para extraer información"), vbExclamation

Exit Sub

Else

X = 0

Do While archi <> ""

Workbooks.Open archi

Cells.Find(What:="UUID", After:=ActiveCell, LookIn:=xlFormulas, LookAt _

:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _

False, SearchFormat:=False).Activate

ActiveCell.Offset(1, 0).Select

identificador = ActiveCell.Value

Cells.Find(What:="@folio", After:=ActiveCell, LookIn:=xlFormulas, LookAt _

:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _

False, SearchFormat:=False).Activate

ActiveCell.Offset(1, 0).Select

folio = ActiveCell.Value

Cells.Find(What:="cfdi:Emisor/@rfc", After:=ActiveCell, LookIn:=xlFormulas, LookAt _

:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _

False, SearchFormat:=False).Activate

ActiveCell.Offset(1, 0).Select

rfc = ActiveCell.Value

Cells.Find(What:="cfdi:Emisor/[uSER=151795]@nombre[/uSER]", After:=ActiveCell, LookIn:=xlFormulas, LookAt _

:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _

False, SearchFormat:=False).Activate

ActiveCell.Offset(1, 0).Select

emisor = ActiveCell.Value

Windows("Extraccion_datos").Activate

Range("A2").Select

Do While ActiveCell.Value <> ""

ActiveCell.Offset(1, 0).Select

Loop

ActiveCell.Value = emisor

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = rfc

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = folio

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = identificador

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = ruta & "\" & archi

Workbooks(archi).Close

archi = Dir()

X = X + 1

Loop

Application.ScreenUpdating = True

MsgBox ("Se han extraido los datos de " & X & " archivos exitosamente"), vbInformation

End If

End Sub

Sub Open_Files()

Dim Hoja As Object

Application.ScreenUpdating = False

'Definir la variable como tipo Variante

Dim X As Variant

'Abrir cuadro de dialogo

X = Application.GetOpenFilename _

("Excel Files (*.xlsx), *.xlsx", 2, "Abrir archivos", , True)

'Validar si se seleccionaron archivos

If IsArray(X) Then ' Si se seleccionan

'Crea Libro nuevo

Workbooks.Add

'Captura nombre de archivo destino donde se grabaran los archivos seleccionados

A = ActiveWorkbook.Name

'*/********************

For y = LBound(X) To UBound(X)

Application.StatusBar = "Importando Archivos: " & X(y)

Workbooks.Open X(y)

b = ActiveWorkbook.Name

For Each Hoja In ActiveWorkbook.Sheets

Hoja.Copy After:=Workbooks(A).Sheets(Workbooks(A).Sheets.Count)

Next

Workbooks(B).Close False

Next

Application.StatusBar = "Listo"

Call Unir_Hojas

End If

Application.ScreenUpdating = False

End Sub

Sub Unir_Hojas()

Dim Sig As Byte, Eliminar As Boolean

For Sig = 2 To Worksheets.Count

Worksheets(Sig).UsedRange.Copy _

Worksheets(1).Range("a1000000").End(xlUp).Offset(1)

Next

Application.DisplayAlerts = False

For Sig = 2 To Worksheets.Count

Worksheets(2).Delete

Next

Application.DisplayAlerts = True

End Sub

ELIMINAR ELEMENTOS REPETIDOS

Sub EliminarFilas()

Dim objDic As Object, i As Integer

Set objDic = CreateObject("Scripting.Dictionary")

Application.ScreenUpdating = False

i = 2

Do While Cells(i, "A") <> ""

'Ajustar a columna criterio, en este ejemplo las columna criterio son

'las columnas A, B y D.

If Not objDic.Exists(Cells(i, "A") & Cells(i, "B") & Cells(i, "D")) Then

objDic.Add Cells(i, "A") & Cells(i, "B") & Cells(i, "D"), 1

i = i + 1

Else

Rows(i).EntireRow.Delete

End If

Loop

Set objDic = Nothing

Application.ScreenUpdating = True

End Sub

  • Silvia bloqueó este tema

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

  • 109 ¿Te parecen útiles los tips de las funciones? (ver tema completo)

    1. 1. ¿Te parecen útiles los tips de las funciones?


      • No
      • Ni me he fijado en ellos

  • Ayúdanos a mejorar la comunidad

    • Donaciones recibidas este mes: 0.00 EUR
      Objetivo: 130.00 EUR
  • Archivos

  • Estadísticas de descargas

    • Archivos
      188
    • Comentarios
      98
    • Revisiones
      29

    Más información sobre "Cambios en el Control Horario"
    Última descarga
    Por pegones1

    4    1

  • Crear macros Excel

  • Mensajes

    • Hola, veo que tienes 365, así que esta forma funcionará   Almacen.xlsx
    • Buenos días  @LeandroA espero estes bien Tengo un caso idéntico al planteado en la siguiente pregunta: Sin embargo, a diferencia de quien planteo originalmente la pregunta al correr el código no obtengo ningún resultado podrían ayudarme a resolver este inconveniente y que al hacer click en el Botón Guardar (CommandButton3) del Formulario RCS (frmrcs) el archivo pdf quede configurado con orientación vertical, márgenes superior, inferior, derecho e izquierdo = 1 y en página tamaño carta. Si acaso influye uso Microsoft Excel LTSC MSO (versión 2209 Compilación16.0.1.15629.20200) de 64 bits Mucho le sabre agradecer la ayuda que me pueda dar  RCS PRUEBA - copia.xlsm
    • @JSDJSDCon gusto mi estimado Para la opción 1: Sub Surtirhastadondealcanse() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets(1) Dim filaInicio As Integer: filaInicio = 4 Dim filaFin As Integer: filaFin = 7 Dim colInventario As Integer: colInventario = 2 Dim colSolicitudesInicio As Integer: colSolicitudesInicio = 4 ' Columna C Dim colResultadoInicio As Integer: colResultadoInicio = 9 ' Columna I Dim colTotalSurtido As Integer: colTotalSurtido = 12 ' Columna L Dim colFinalInventario As Integer: colFinalInventario = 13 ' Columna M Dim numClientes As Integer: numClientes = 3 Dim fila As Integer, i As Integer For fila = filaInicio To filaFin Dim inventario As Double inventario = Val(ws.Cells(fila, colInventario).Value) Dim solicitudes(1 To 3) As Double Dim surtido(1 To 3) As Variant Dim totalSurtido As Double: totalSurtido = 0 ' Leer solicitudes For i = 1 To numClientes If IsNumeric(ws.Cells(fila, colSolicitudesInicio + i - 1).Value) Then solicitudes(i) = CDbl(ws.Cells(fila, colSolicitudesInicio + i - 1).Value) Else solicitudes(i) = 0 End If surtido(i) = "POR FALTA STOCK" Next i ' Surtir de acuerdo al inventario disponible For i = 1 To numClientes If solicitudes(i) > 0 Then If inventario >= solicitudes(i) Then surtido(i) = solicitudes(i) inventario = inventario - solicitudes(i) totalSurtido = totalSurtido + solicitudes(i) ElseIf inventario > 0 Then surtido(i) = inventario totalSurtido = totalSurtido + inventario inventario = 0 Else surtido(i) = "POR FALTA STOCK" End If End If Next i ' Escribir resultados en las columnas correspondientes para cada cliente For i = 1 To numClientes With ws.Cells(fila, colResultadoInicio + i - 1) If surtido(i) = "POR FALTA STOCK" Then .Value = surtido(i) .Font.Color = vbRed Else .Value = surtido(i) .Font.Color = vbBlack End If End With Next i ' Escribir total surtido y existencia final ws.Cells(fila, colTotalSurtido).Value = totalSurtido ws.Cells(fila, colFinalInventario).Value = inventario Next fila MsgBox "Resultado surtido cargado con éxito...", vbInformation End Sub Para la opción 2:   Sub surtirenpartesiguales() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets(1) Dim filaInicio As Integer: filaInicio = 13 Dim filaFin As Integer: filaFin = 16 Dim colInventario As Integer: colInventario = 2 Dim colSolicitudesInicio As Integer: colSolicitudesInicio = 4 ' Columna C Dim colResultadoInicio As Integer: colResultadoInicio = 9 ' Columna I Dim colTotalSurtido As Integer: colTotalSurtido = 12 ' Columna L Dim colFinalInventario As Integer: colFinalInventario = 13 ' Columna M Dim numClientes As Integer: numClientes = 3 Dim fila As Integer, i As Integer For fila = filaInicio To filaFin Dim inventario As Double inventario = Val(ws.Cells(fila, colInventario).Value) Dim solicitudes(1 To 3) As Double Dim surtido(1 To 3) As Variant Dim totalSurtido As Double: totalSurtido = 0 Dim totalPedido As Double: totalPedido = 0 ' Leer solicitudes For i = 1 To numClientes If IsNumeric(ws.Cells(fila, colSolicitudesInicio + i - 1).Value) Then solicitudes(i) = CDbl(ws.Cells(fila, colSolicitudesInicio + i - 1).Value) totalPedido = totalPedido + solicitudes(i) Else solicitudes(i) = 0 End If surtido(i) = 0 Next i ' Si hay suficiente inventario, surtir lo que el cliente pide If inventario >= totalPedido Then For i = 1 To numClientes If solicitudes(i) > 0 And inventario >= solicitudes(i) Then surtido(i) = solicitudes(i) inventario = inventario - solicitudes(i) totalSurtido = totalSurtido + solicitudes(i) End If Next i Else ' Reparto base igualitario Dim baseSurtido As Long baseSurtido = Int(inventario / numClientes) For i = 1 To numClientes If solicitudes(i) > 0 Then If solicitudes(i) <= baseSurtido Then surtido(i) = solicitudes(i) inventario = inventario - solicitudes(i) totalSurtido = totalSurtido + solicitudes(i) Else surtido(i) = baseSurtido inventario = inventario - baseSurtido totalSurtido = totalSurtido + baseSurtido End If End If Next i ' Repartir sobrante restante uno por uno, respetando lo pedido Do While inventario > 0 For i = 1 To numClientes If surtido(i) < solicitudes(i) Then surtido(i) = surtido(i) + 1 totalSurtido = totalSurtido + 1 inventario = inventario - 1 If inventario = 0 Then Exit For End If Next i Loop End If ' Escribir resultados en las columnas correspondientes para cada cliente For i = 1 To numClientes With ws.Cells(fila, colResultadoInicio + i - 1) If surtido(i) = 0 Then .Value = "POR FALTA STOCK" .Font.Color = vbRed Else .Value = surtido(i) .Font.Color = vbBlack End If End With Next i ' Escribir total surtido y existencia final ws.Cells(fila, colTotalSurtido).Value = totalSurtido ws.Cells(fila, colFinalInventario).Value = inventario Next fila MsgBox "Resultado surtido cargado con éxito...", vbInformation End Sub Saludos, Diego
    • Buenos dias.  Estoy trabajando en una hoja para poder llevar un control de un pequeño almacén.  Tengo un pedido con varias líneas y "lotes" y necesito sacar las ubicaciones que coincidan con la referencia y lote que pone en el pedido. El problema viene cuando tengo la misma referencia y mismo lote en ubicaciones diferentes y necesito sacar la información en columnas diferentes. No se si  me he explicado bien, pero creo que con el ejemplo adjunto se entiende mejor. Agradecería mucho si me pudieran ayudar  Libro1.xlsx
    • Exelente solución mil gracias 
  • Visualizado recientemente

    • No hay usuarios registrado para ver esta página.
×
×
  • Crear nuevo...

Información importante

Echa un vistazo a nuestra política de cookies para ayudarte a tener una mejor experiencia de navegación. Puedes ajustar aquí la configuración. Pulsa el botón Aceptar, si estás de acuerdo.