Visual Basic para Aplicaciones - Macro no funciona con tecla acceso rapido

Life is soft - evento anual de software empresarial
 
Vista:

Macro no funciona con tecla acceso rapido

Publicado por Mario (1 intervención) el 30/01/2023 20:50:51
Buenas tardes, me encuentro con algo inexplicable para mi. Creé un macro para formatear la información de un archivo que bajo desde una cuenta bancaria para insertarla en otro archivo que se encuentra en un servidor. El problema radica en que funciona perfecto si ejecuto la macro desde la solapa de macros, pero si ejecuto dicha macro con la combinación de teclas que le asigné, no la completa a la ejecución, es decir cuando llega el momento de abrir el archivo de Destino no ejecuta el resto. Esta es la macro.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Sub Echeqs()
Dim I, CELDAS
Dim Fuente As Workbook
Dim Destino As Workbook
Dim NombreDeArchivo As String
Dim ExisteArchivo As String
 
  If ActiveWorkbook.Name = "listaEcheq.xls" Then
 
    Set Fuente = ActiveWorkbook
 
   'Compruebo si existe el archivo Echeqs
 
    NombreDeArchivo = "\\192.168.1.2\Sistema_Nuevo\Bancos\Echeqs.xlsx"
    ExisteArchivo = Dir(NombreDeArchivo)
 
    If ExisteArchivo = "" Then
      MsgBox "No puedo abrir el archivo de Echeqs"
    Else
 
       Cells.Select
       With Selection
           '.WrapText = False
           .Orientation = 0
           .AddIndent = False
           .IndentLevel = 0
           .ShrinkToFit = False
           .ReadingOrder = xlContext
           .HorizontalAlignment = xlGeneral
           .VerticalAlignment = xlTop
           .MergeCells = False
           .Font.Name = "Arial"
           .Font.Size = 10
       End With
 
       Selection.UnMerge
 
       'BORRO LA COLUMNA DE ESTADO
       Columns("G:G").Select
       Selection.Delete Shift:=xlToLeft
 
       Range("G5").Select
 
       'FILTRO LA COLUMNA DE IMPORTE PARA QUEDARME CON LOS DATOS QUE SIRVEN
       I = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
       CELDAS = "$A$5:$G$" & Trim(Str(I))
       ActiveSheet.Range(CELDAS).AutoFilter Field:=7, Criteria1:="<>"
 
       Range("G5").Select
       I = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
 
       'FORMATEO A FECHA LA COLUMNA DE FECHAS Y LO CENTRO
       Range(Cells(5, 5), Cells(I, 6)).Select
       Selection.NumberFormat = "m/d/yyyy"
       Selection.HorizontalAlignment = xlCenter
 
       'FORMATEO A NUMERO LA COLUMNA DE IMPORTE
       Range(Cells(5, 7), Cells(I, 7)).Select
       Selection.NumberFormat = "#,##0.00_ ;[Red]-#,##0.00 "
 
       'CENTRO EL NUMERO DE ECHEQ
       Range(Cells(5, 4), Cells(I, 4)).Select
       Selection.HorizontalAlignment = xlCenter
 
       'ABRO EL ARCHIVO DESTINO
       Set Destino = Workbooks.Open(NombreDeArchivo)
 
       'SELECCIONO EL ARCHIVO ORIGEN
       Fuente.Activate
 
       'COPIO LA INFORMACION
       Range(Cells(5, 2), Cells(I, 8)).Select
       Selection.Copy
 
       'SELECCIONO ARCHIVO DESTINO
       Destino.Activate
 
       'ME PARO EN EL ULTIMO RENGLON DE INFORMACION
       I = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1
 
       'PEGO LO COPIADO DESDE EL ARCHIVO BAJADO
       Range(Cells(I, 1), Cells(I, 1)).PasteSpecial xlPasteAll
 
       'CIERRO LOS LIBRO
 
       Destino.Close SaveChanges:=True
 
       Fuente.Close SaveChanges:=False
 
    End If
 
  End If
 
End Sub

Otro dato curioso es, si abro el archivo Destino después de seleccionar la información que voy a pasar, me da error de open.
Agradeceré todas las ideas que puedan darme. Muchas gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder