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 viernes a las 17:19 2 días
Hola amigos
quisiera saber si alguien me puede ayudar con lo siguiente:
Tengo un userform con dos combobox un commandbutton, un listbox y un textbox.
de los cuales los combobox buscan fechas inicial y final de una hoja de calculo y al ejecutar el boton muestra en el listbox todos los resultados entre esas fechas incluidas las mismas, estos resultados debieran ser 4 columnas en la primera la cantidad en la segunda el articulo o producto en la tercera el precio y en la ultima el total, además en el textbox debe aparecer la suma de todos los totales el codigo que estoy utilizando es:
Private Sub CommandButton1_Click()
ListBox2.Clear
Dim fecha1 As Date
Dim fecha2 As Date
Do While ComboBox2.Value = "" Or ComboBox3.Value = ""
UserForm35.Show
Exit Sub
Loop
fecha1 = ComboBox2.Value
fecha2 = ComboBox3.Value
Sheets("INFORMES").Activate
Range("e2").Activate
Do While ActiveCell.Value <> ""
If ActiveCell.Value = fecha1 Then
Exit Do
Else
ActiveCell.Offset(1, 0).Activate
End If
Loop
Do While ActiveCell.Value <> fecha2
ListBox2.AddItem ActiveCell.Offset(0, -4).Value
c = ListBox2.ListCount - 1
ListBox2.List(c, 1) = ActiveCell.Offset(0, -1).Value
ActiveCell.Offset(1, 0).Activate
Loop
suma2 = suma2 + ActiveCell.Offset(0, -1).Value
For p = 0 To ListBox2.ListCount - 1
suma2 = suma2 + CDbl(ListBox2.List(p, 1))
Next
TextBox2.Value = suma2
TextBox2.Value = Format(TextBox2, "#,##0.00")
End Sub
Private Sub UserForm_Initialize()
Sheets("INFORMES").Activate
Range("e1").CurrentRegion.Sort Key1:=Range("e1"), Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("e2").Activate
Do While ActiveCell.Value <> ""
If InStr(valores, ActiveCell) = 0 Then
valores = valores & "," & ActiveCell
End If
ActiveCell.Offset(1, 0).Activate
Loop
valores = Mid(valores, 2, Len(valores) - 1)
valores = Split(valores, ",")
For X = 0 To UBound(valores)
ComboBox2.AddItem valores(X)
ComboBox3.AddItem valores(X)
Next
End Subpero solo muestra dos columnas la primera es el producto y la segunda es el valory en textbox la suma, pero no muestra nada en el listbox si las fechas son iguales, pero si muestra la suma de esa fecha. ayuda por favor