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
Buenos dias:
Tengo una base de datos y en mi codigo uso el vlookup para traer informacion de esa base a un userform, lo que necesito es incluirle un mensaje de alerta cuando se digite el codigo equivocado y por tanto no se encuentra en la base de datos, alctualemnte si se digita mal lo que hace es sacarme al codigo.
Gracias por su colaboracion...
el codigo es el siguiente
Private Sub CommandButton1_Click()
If Reclamacion = "" Then
Numero_de_Factura = "": Exit Sub
total_facturado_mdqx = "": Exit Sub
total_reclamado_mdqx = "": Exit Sub
Primer_apellido_de_la_victima = "": Exit Sub
Segundo_apellido_de_la_vicitima = "": Exit Sub
Primer_nombre_de_la_victima = "": Exit Sub
Segundo_nombre_de_la_victima = "": Exit Sub
Tipo_de_documentode_identidad_de_la_victima = "": Exit Sub
Fecha_de_ocurrencia_del_evento = "": Exit Sub
Fecha_de_ingreso = "": Exit Sub
Fecha_de_egreso = "": Exit Sub
End If
Numero_de_Factura = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 2, 0)
total_facturado_mdqx = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 12, 0)
total_reclamado_mdqx = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 13, 0)
Primer_apellido_de_la_victima = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 8, 0)
Segundo_apellido_de_la_vicitima = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 9, 0)
Primer_nombre_de_la_victima = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 10, 0)
Segundo_nombre_de_la_victima = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 11, 0)
Tipo_de_documentode_identidad_de_la_victima = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 6, 0)
Numero_de_documento_de_la_identidad_de_la_victima = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 7, 0)
Fecha_de_ocurrencia_del_evento = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 3, 0)
Fecha_de_ingreso = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 4, 0)
Fecha_de_egreso = Application.VLookup(Val(Reclamacion), Sheets("DATOS").Range("A2:N20000"), 5, 0)