Visual Basic - ERROR 32809 no me permite procesar comprobantes que estén echos en otros windows

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

ERROR 32809 no me permite procesar comprobantes que estén echos en otros windows

Publicado por Carlos Quintero (2 intervenciones) el 31/03/2016 01:16:26
buenas noches,

realice una macro pero al ejecutarla solo me lee comprobantes echos en el windows de mi pc los demas me arroja error 32809

adjunto la macro donde me esta poniendo problema,

agradezco la ayuda para que me pueda leer comprobantesrealizados en diferentes windows

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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
 '** API para buscar ventanas abiertas **
Private Declare Function findwindow Lib "user32" Alias "FindWindowA" (ByVal lpclassname As String, ByVal lpwindowname As String) As Long
 
      ' ** Variable Globales al Módulo **
 
Dim UFcomprobante As Integer 'Guarda la Última Fila de Cada comprobante que va abriendo
Dim NumeroComprobante As String 'Guarda el # del Comprobante de Cada comprobante que va abriendo
Dim Fecha As String 'Guarda la Fecha de Cada comprobante que va abriendo
Dim RutaProcesados As String
Dim RutaComprobantes As String
 
Public Function CORRELATIVIDAD() As String
Application.Volatile
For hc = 1 To 50
PLANILLA = "Compte Nro " & hc
Sheets(PLANILLA).Select
    ult = Cells(1010, 3).End(xlUp).Row
    For i = 11 To ult
        For j = 2 To 16
            If ThisWorkbook.Sheets(PLANILLA).Cells(i, 3) = ThisWorkbook.Sheets("CENTRO DE COSTOS").Cells(j, 14) Then
                CORR = CORR + 1
            End If
        Next
    Next
    If CORR > 0 Then
        CCC = hc + 8
        ThisWorkbook.Sheets("PlanillaComp").Select
        ThisWorkbook.Sheets("PlanillaComp").Cells(CCC, 14) = "Correlatividad"
        CORR = 0
    End If
Next
 
End Function
 
 
' ** Valida la estructura del comprobante.
'    Retorna "OK" si está correcta, de lo contrario retorna la inconsistencia que presenta
'    Guarda la última fila del comprobante en la variable 'UFcomprobante'
 
Function ValidarEstructuraComprobante() As String
    On Error GoTo Errores
    Dim i As Integer
 
    If ActiveSheet.Range("B10") <> "OFC" Or ActiveSheet.Range("C10") <> "Cuenta PUC" Or _
       ActiveSheet.Range("D10") <> "NOMBRE CTA PUC" Or ActiveSheet.Range("E10") <> "MONEDA" Or _
       ActiveSheet.Range("f10") <> "COD TRN" Or ActiveSheet.Range("G10") <> "VALOR" Or _
       ActiveSheet.Range("H10") <> "TASA" Or ActiveSheet.Range("I10") <> "MONTO EQUIVALENTE" Or _
       ActiveSheet.Range("J10") <> "DESCRIPCION" Or ActiveSheet.Range("J7") <> "Total Débitos monto  equivalente" Or _
       ActiveSheet.Range("J8") <> "Total Créditos monto equivalente" Or ActiveSheet.Range("K4") <> "F E C H A      E F E C T I V A" Or _
       ActiveSheet.Range("B6") <> "Area responsable de este comprobante" Then
 
 
       '** Quita la proteccion del comprobante
Desprotejer
            ' ** Rellena con amarillo las celdas que no tienen el dato esperado **
       If ActiveSheet.Range("B10") <> "Ofc" Then ActiveSheet.Range("B10").Interior.Color = 65535
       If ActiveSheet.Range("C10") <> "Cuenta PUC" Then ActiveSheet.Range("C10").Interior.Color = 65535
       If ActiveSheet.Range("D10") <> "NOMBRE CTA PUC" Then ActiveSheet.Range("D10").Interior.Color = 65535
       If ActiveSheet.Range("E10") <> "MONEDA" Then ActiveSheet.Range("E10").Interior.Color = 65535
       If ActiveSheet.Range("f10") <> "COD TRN" Then ActiveSheet.Range("f10").Interior.Color = 65535
       If ActiveSheet.Range("G10") <> "VALOR" Then ActiveSheet.Range("G10").Interior.Color = 65535
       If ActiveSheet.Range("H10") <> "TASA" Then ActiveSheet.Range("H10").Interior.Color = 65535
       If ActiveSheet.Range("I10") <> "MONTO EQUIVALENTE" Then ActiveSheet.Range("I10").Interior.Color = 65535
       If ActiveSheet.Range("J10") <> "DESCRIPCION" Then ActiveSheet.Range("J10").Interior.Color = 65535
       If ActiveSheet.Range("J7") <> "Total Débitos monto  equivalente" Then ActiveSheet.Range("J7").Interior.Color = 65535
       If ActiveSheet.Range("J8") <> "Total Créditos monto equivalente" Then ActiveSheet.Range("J8").Interior.Color = 65535
       If ActiveSheet.Range("K4") <> "F E C H A      E F E C T I V A" Then ActiveSheet.Range("K4").Interior.Color = 65535
       If ActiveSheet.Range("B6") <> "Area responsable de este comprobante" Then ActiveSheet.Range("B6").Interior.Color = 65535
       '** Pone la proteccion del comprobante
       ActiveSheet.Protect
        '** Guarda el comprobante
       ActiveWorkbook.Save
 
       ValidarEstructuraComprobante = "Estructura no válida"
       Exit Function
    End If
 
              '** Halla la última fila del comprobante. Si no hay registros o hay más de 1,000 no lo carga **
    ActiveSheet.Range("C10").Select
    UFcomprobante = Cells(10, 3).End(xlDown).Row
    If ActiveCell.Row > 1010 Then
    MsgBox "El Comprobante '" & ActiveWorkbook.Name & "' Tienes mas de 1000 registros!!" & Chr(13) & Chr(13) & "SE DEBE DEVOLVER EL COMPROBANTE!!!", vbCritical, "Supera los 1000 Registros"
       ValidarEstructuraComprobante = "No hay registros (o superan los 1,000)"
       UFcomprobante = 0
       Exit Function
    End If
 
 
    '** Recorre los reg. del comrpob. validando si hay valores en cero, negativos o con mas de dos decimales**
For i = 11 To UFcomprobante
    If ActiveSheet.Cells(i, 7) <> "" Then 'Si la fila no está vacía
        Valr = ActiveSheet.Cells(i, 7)
        vlvr = Format(Valr, "###,###.00")
        vlvr1 = Format(Valr, "###,###.00000000")
        t = vlvr1 - vlvr
        t = Format(t, ".000000000000")
        If t <> 0 Then
           MsgBox "Se ha encontrado un registro con mas de dos decimales" & Chr(13) & Chr(13) & "SE DEBE DEVOLVER EL COMPROBANTE!!!" & Chr(13) & Chr(13) & "Valor Aceptado: $ " & vlvr & Chr(13) & Chr(13) & "Valor del Comprobante: $ " & vlvr1 & Chr(13) & Chr(13) & "Diferencia: $ " & t, vbExclamation, "VALOR EN MAS DE DOS DECIMALES"
           ValidarEstructuraComprobante = "Valores con mas de 2 decimales"
           Exit Function
        End If
 
        Valr4 = ActiveSheet.Cells(i, 9)
        vlvr4 = Format(Valr4, "###,###.00")
        vlvr5 = Format(Valr4, "###,###.00000000")
        t = vlvr5 - vlvr4
        t = Format(t, ".000000000000")
        If t <> 0 Then
           MsgBox "Se ha encontrado un registro con mas de dos decimales" & Chr(13) & Chr(13) & "SE DEBE DEVOLVER EL COMPROBANTE!!!" & Chr(13) & Chr(13) & "Valor Aceptado: $ " & vlvr4 & Chr(13) & Chr(13) & "Valor del Comprobante: $ " & vlvr5 & Chr(13) & Chr(13) & "Diferencia: $ " & t, vbExclamation, "VALOR EN MAS DE DOS DECIMALES"
           ValidarEstructuraComprobante = "Valores con mas de 2 decimales"
           Exit Function
        End If
 
        If ActiveSheet.Range("G" & i) = 0 Then
           MsgBox "Se ha encontrado un registro con valor en CERO" & Chr(13) & Chr(13) & "SE DEBE DEVOLVER EL COMPROBANTE!!!", vbExclamation, "VALOR EN CERO"
           ValidarEstructuraComprobante = "Registro con Valor CERO"
           Exit Function
        End If
        If ActiveSheet.Range("G" & i) < 0 Then
           MsgBox "Se ha encontrado un registro con valor NEGATIVO" & Chr(13) & Chr(13) & "SE DEBE DEVOLVER EL COMPROBANTE!!!", vbExclamation, "VALOR NEGATIVO"
           ValidarEstructuraComprobante = "Registro con Valor NEGATIVO"
           Exit Function
        End If
      End If
  Next
 
          ' ** Valida si el comprobante está protegido **
    If Not ValidarProtection Then
         If MsgBox("El Comprobante '" & ActiveWorkbook.Name & "' No está protegido!!!" & Chr(13) & Chr(13) & "Realmente desea cargarlo?", vbYesNo, "COMPROBANTE DESPROTEGIDO") = vbNo Then
            ValidarEstructuraComprobante = "Comprobante desprotegido"
            Application.ScreenUpdating = False
            Exit Function
         End If
    End If
 
    '** Valida si el comprobante esta descuadrado**
    If Not CUADRADO Then
           MsgBox "El comprobante esta Descuadrado" & Chr(13) & Chr(13) & "SE DEBE DEVOLVER EL COMPROBANTE!!!", vbExclamation, "VALOR NEGATIVO"
           ValidarEstructuraComprobante = "Comprobante descuadrado"
           Exit Function
        End If
 
    '** Valida si el comprobante es de otro mes**
    A = Format(ActiveSheet.Range("L5"), "00")
    ms = Format(Now, "mm")
    If A < ms Then
    If MsgBox("El Comprobante '" & ActiveWorkbook.Name & "' Es del Periodo anterior!!!" & Chr(13) & Chr(13) & "Realmente desea cargarlo?", vbYesNo, "COMPROBANTE DEL PERIODO ANTERIOR") = vbNo Then
    ValidarEstructuraComprobante = "Comprobante del periodo anterior"
          Application.ScreenUpdating = False
          Exit Function
    End If
    End If
 
          ' ** Si la fecha Contable es anterior a 15 días, solicita confirmación para cargar el comrobante **
    A = Format(ActiveSheet.Range("l5"), "00")
    facf = Format(ActiveSheet.Range("K5"), "00") & "/" & Format(ActiveSheet.Range("l5"), "00") & "/" & ActiveSheet.Range("M5")
    FechaCompte = Format(facf, "DD/MMM/YYYY")
    ThisWorkbook.Sheets("CENTRO DE COSTOS").Cells(3, 8) = FechaCompte
    ThisWorkbook.Sheets("CENTRO DE COSTOS").Calculate
    DIAS = ThisWorkbook.Sheets("CENTRO DE COSTOS").Cells(4, 8)
    If DIAS > 15 Then
       Application.ScreenUpdating = True
       If MsgBox("El Comprobante '" & ActiveWorkbook.Name & "' Tiene una Fecha Contable anterior a 15 días!!!" & Chr(13) & Chr(13) & "Realmente desea cargarlo?", vbYesNo, "FECHA DE COMPROBANTE MAYOR A 15 DÍAS") = vbNo Then
          ValidarEstructuraComprobante = "Fecha contable anterior a 15 días"
          Application.ScreenUpdating = False
          Exit Function
       End If
       Application.ScreenUpdating = False
    Else
            ' ** Revisa si la fecha del comprobante es inferior a 3 días hábiles **
      If DIAS > 3 Then
         Application.ScreenUpdating = True
         If MsgBox("El Comprobante '" & ActiveWorkbook.Name & "' Tiene una Fecha Contable anterior a 3 días hábiles!!!" & Chr(13) & Chr(13) & "Realmente desea cargarlo?", vbYesNo, "FECHA DE COMPROBANTE MAYOR A 3 DÍAS HÁBILES") = vbNo Then
            ValidarEstructuraComprobante = "Fecha contable anterior a 3 días hábiles"
            Application.ScreenUpdating = False
            Exit Function
         End If
         Application.ScreenUpdating = False
      End If
    End If
 
    On Error Resume Next
    If Cells(2, 5) = "No_Rutinaria" Then
        If MsgBox("El Comprobante '" & ActiveWorkbook.Name & "' requiere firma de GERENTE!!!" & Chr(13) & Chr(13) & "Comprobante Firmado por: " & Range("NOMBRE_APROBADOR") & Chr(13) & Chr(13) & "Desea Continuar?", vbYesNo, "COMPROBANTE REQUIERE FIRMA DE GERENTE") = vbNo Then
            ValidarEstructuraComprobante = "Comprobante no esta firmado por gerente"
            Exit Function
         End If
        End If
 
    ' ** si requiere firma de gerente muestra el nombre del gerente**
      If FIRMAGERENTE = "OK" Then
        On Error GoTo Errores
        If Range("NOMBRE_APROBADOR") <> "" Then
        If MsgBox("El Comprobante '" & ActiveWorkbook.Name & "' requiere firma de GERENTE!!!" & Chr(13) & Chr(13) & "Comprobante Firmado por: " & Range("NOMBRE_APROBADOR") & Chr(13) & Chr(13) & "Desea Continuar?", vbYesNo, "COMPROBANTE REQUIERE FIRMA DE GERENTE") = vbNo Then
            ValidarEstructuraComprobante = "Comprobante no esta firmado por gerente"
            Exit Function
         End If
 
      Else
      If Range("NOMBRE_APROBADOR") = "" Then
      If MsgBox("El Comprobante '" & ActiveWorkbook.Name & "' requiere firma de GERENTE!!!" & Chr(13) & Chr(13) & "El sistema no ha podido establecer quien Aprobó el Comprobante" & Chr(13) & Chr(13) & "Desea Continuar?", vbYesNo, "COMPROBANTE REQUIERE FIRMA DE GERENTE") = vbNo Then
            ValidarEstructuraComprobante = "Comprobante no esta firmado por gerente"
            Exit Function
         End If
    End If
    End If
    End If
    ValidarEstructuraComprobante = "OK" '
  Exit Function
Errores: Call TratarError(Err.Number, Err.Description, "ValidarEstructuraComprobante")
End Function
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