Sub Imagen13_Haga_clic_en()
Dim Izq As Single, Arr As Single, Ancho As Single, Alto As Single
Dim rutaArchivo As String
Dim Email As CDO.Message
Dim t As Single
Application.DisplayAlerts = False
Application.ScreenUpdating = False
ActiveSheet.Unprotect "4324"
'--- GENERAR IMAGEN DEL RECIBO ---
With Range("H7:R34")
Izq = .Left: Arr = .Top: Ancho = .Width: Alto = .Height
.CopyPicture
End With
With ActiveSheet.ChartObjects.Add(Izq, Arr, Ancho, Alto)
.Activate
.Chart.Paste
'---- RUTA DEL ARCHIVO (CORREGIDO) ----
rutaArchivo = "C:\Users\Usuario\Google Drive\LOCACIONES\REC. PROPIETARIOS\" & _
Format(Range("Q20"), "mmmYY") & " - " & _
Range("Q9") & " - " & _
Range("P17") & " - " & _
Range("K19") & ".JPG"
.Chart.Export rutaArchivo
.Delete
End With
'Guardar ruta en AK30 por compatibilidad
Range("AK30").Value = rutaArchivo
'--- PEGAR BLOQUE DE DATOS ---
Range("AH6").Copy
Range("AH9").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Range("Y7:AI33").Copy
Range("H7").PasteSpecial xlPasteAll
ActiveSheet.Protect "4324"
ActiveWorkbook.Save
'--- PREPARAR ENVÍO DEL MAIL ---
Set Email = New CDO.Message
correo_origen = "nqn.negocios@gmail.com"
Clave_correo_origen = "wkfhaapcnjljbwju"
correo_destino = Range("AK27").Value
Asunto = Range("AK28")
Mensaje = Range("AK29")
Email.Configuration.Fields(cdoSMTPServer) = "smtp.gmail.com"
Email.Configuration.Fields(cdoSendUsingMethod) = 2
With Email.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = correo_origen
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Clave_correo_origen
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
End With
'--- VALIDAR ARCHIVO ANTES DE ENVIAR ---
t = Timer
Do While Dir(rutaArchivo) = "" And Timer - t < 5
DoEvents
Loop
If Dir(rutaArchivo) = "" Then
MsgBox "ERROR: El archivo no se generó: " & rutaArchivo, vbCritical
Exit Sub
End If
'--- ENVIAR MAIL ---
With Email
.To = correo_destino
.From = correo_origen
.Subject = Asunto
.TextBody = Mensaje
.Configuration.Fields.Update
.AddAttachment rutaArchivo
On Error Resume Next
.Send
End With
End Sub
Sub powerbuttonINQ()
Dim Izq As Single, Arr As Single, Ancho As Single, Alto As Single
Dim rutaArchivo As String
Dim Email As CDO.Message
Dim t As Single
Application.DisplayAlerts = False
Application.ScreenUpdating = False
ActiveSheet.Unprotect "4324"
'--- GENERAR IMAGEN DEL RECIBO ---
With Range("H7:R33")
Izq = .Left: Arr = .Top: Ancho = .Width: Alto = .Height
.CopyPicture
End With
With ActiveSheet.ChartObjects.Add(Izq, Arr, Ancho, Alto)
.Activate
.Chart.Paste
rutaArchivo = "C:\Users\Usuario\Google Drive\LOCACIONES\REC. INQUILINOS\" & _
Format(Range("Q20"), "mmmYY") & " - " & _
Range("Q9") & " - " & _
Range("P17") & " - " & _
Range("J17") & ".JPG"
.Chart.Export rutaArchivo
.Delete
End With
Range("AK30").Value = rutaArchivo
Range("AH6").Copy
Range("AH9").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Range("Y7:AI33").Copy
Range("H7").PasteSpecial xlPasteAll
ActiveSheet.Protect "4324"
ActiveWorkbook.Save
'--- EMAIL CONFIG ---
Set Email = New CDO.Message
correo_origen = "nqn.negocios@gmail.com"
Clave_correo_origen = "wkfhaapcnjljbwju"
correo_destino = Range("AK27").Value
Asunto = Range("AK28")
Mensaje = Range("AK29")
Email.Configuration.Fields(cdoSMTPServer) = "smtp.gmail.com"
Email.Configuration.Fields(cdoSendUsingMethod) = 2
With Email.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = correo_origen
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Clave_correo_origen
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
End With
'--- VERIFICAR ARCHIVO ---
t = Timer
Do While Dir(rutaArchivo) = "" And Timer - t < 5
DoEvents
Loop
If Dir(rutaArchivo) = "" Then
MsgBox "ERROR: El archivo no se generó: " & rutaArchivo, vbCritical
Exit Sub
End If
'--- ENVIAR ---
With Email
.To = correo_destino
.From = correo_origen
.Subject = Asunto
.TextBody = Mensaje
.Configuration.Fields.Update
.AddAttachment rutaArchivo
On Error Resume Next
.Send
End With
End Sub
Por
JSDJSD , · publicado el 5 de diciembre 5 dic
Hola, necesito que me ayuden con este planteamiento. Necesito cargar desde una Hoja de Excel a tres ListBox todos los registros de Cuenta seleccionada de la Hoja Resumen Crat-Cli (Columna A) que encuentre en la Hoja CartolaCli (Cuenta, Razón Social, Vencimiento, Monto o Importe). Estoy usando el método FIND para una búsqueda más dinámica.
En cada ListBox se deben cargar por Clase de Documento:
Factura (DF)
Nota Crédito (DN)
Transacción (DZ-AB-DD)
En el caso de Factura están separado la suma de su importe de acuerdo a la fecha de vencimiento.
-Si la deuda ya venció mayor a 30 días.
-Si la deuda ya venció entre 1 y 30 días.
Me sale error al cargar los registros.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.FormulaR1C1 = "Cuenta" Then
UserForm1.Show
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'On Error Resume Next
Dim UF As String
UserForm1.Fact1.Clear
UserForm1.NotaCredit.Clear
UserForm1.Transacc.Clear
UserForm1.Menor_Mes.Text = Empty
UserForm1.Mayor_Mes.Text = Empty
UserForm1.NC_Total.Text = Empty
UserForm1.Transacc_Total.Text = Empty
UserForm1.Fact_Total.Text = Empty
UserForm1.Monto_Total.Text = Empty
Mayor_Mes = 0
Menor_Mes = 0
NC_Total = 0
Transacc_Total = 0
Set A = Sheets("Cartola Cli")
PF = 2
UF = A.Range("G" & Rows.Count).End(xlUp).Row 'Base de registros
R = "G" & PF & ":G" & UF
Busco = Intersect(Target, Range("A:A"))
Set CODIGO = A.Range(R).Find(Busco, LookIn:=xlValues, lookat:=xlWhole)
If Not CODIGO Is Nothing Then
If Not Busco Is Nothing And Selection.Count = 1 And _
ActiveCell.FormulaR1C1 <> "Cuenta" Then
If A.Cells(CODIGO.Row, 7) = Busco Then
If UCase(A.Cells(CODIGO.Row, 1)) Like "DF" And A.Cells(CODIGO.Row, 10).Value <> "Vigente" Then
UserForm1.Fact1.AddItem A.Cells(CODIGO.Row, 4) 'Vencimiento
UserForm1.Fact1.List(UserForm1.Fact1.ListCount - 1, 1) = A.Cells(CODIGO.Row, 5) 'Monto
UserForm1.Cuenta.Caption = A.Cells(CODIGO.Row, 7) 'Cuenta
UserForm1.RazonSocial.Caption = A.Cells(CODIGO.Row, ? 'Razon Social
If LCase(A.Cells(CODIGO.Row, 10)) Like "0 a 30" Then
Menor_Mes = Menor_Mes + A.Cells(CODIGO.Row, 5)
ElseIf A.Cells(CODIGO.Row, 9) > 30 Then
Mayor_Mes = Mayor_Mes + A.Cells(CODIGO.Row, 5)
End If
ElseIf UCase(A.Cells(CODIGO.Row, 1)) Like "DN" Then
UserForm1.NotaCredit.AddItem A.Cells(CODIGO.Row, 4) 'Vencimiento
UserForm1.NotaCredit.List(UserForm1.NotaCredit.ListCount - 1, 1) = A.Cells(CODIGO.Row, 5) 'Monto
UserForm1.Cuenta.Caption = A.Cells(CODIGO.Row, 7) 'Cuenta
UserForm1.RazonSocial.Caption = A.Cells(CODIGO.Row, ? 'Razon Social
NC_Total = NC_Total + A.Cells(CODIGO.Row, 5)
ElseIf UCase(A.Cells(CODIGO.Row, 1)) Like "DZ" Or UCase(A.Cells(CODIGO.Row, 1)) Like "DD" Or _
UCase(A.Cells(CODIGO.Row, 1)) Like "AB" Then
UserForm1.Transacc.AddItem A.Cells(CODIGO.Row, 4) 'Vencimiento
UserForm1.Transacc.List(UserForm1.Transacc.ListCount - 1, 1) = A.Cells(CODIGO.Row, 5) 'Monto
UserForm1.Cuenta.Caption = A.Cells(CODIGO.Row, 7) 'Cuenta
UserForm1.RazonSocial.Caption = A.Cells(CODIGO.Row, ? 'Razon Social
Transacc_Total = Transacc_Total + A.Cells(CODIGO.Row, 5)
End If
End If
End If
UserForm1.Menor_Mes.Text = Menor_Mes
UserForm1.Mayor_Mes.Text = Mayor_Mes
UserForm1.NC_Total.Text = NC_Total
UserForm1.Transacc_Total.Text = Transacc_Total
UserForm1.Fact_Total.Text = Menor_Mes + Mayor_Mes
UserForm1.Monto_Total.Text = Menor_Mes + Mayor_Mes + NC_Total + Transacc_Total
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub