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,
me estoy metiendo en esto de las macros y me he econtrado un problemilla.
Tengo un libro con un montón de datos que de hecho són vínculos a otros muchos libros. Se llama "Offers". Filtro estos y copio las columnas que me interesan hacia un nuevo libro, "Report".
Funciona bastante bien pero en dos casos ("Margenes" y "Precio") sólo me copia la primera fila de entre las filtradas y no el resto.
Cómo puede ser que funcione bien en algunas columnas y no en otras cuando és exactamente el mismo código? Y los origenes son todos vínculos y el destino tiene formato general de celda.
Muchas gracias por vuestra ayuda, os pego lo que tengo hecho.
Sub filtrar_offers()
'Fechas para filtrar y cambio
Dim lFecha1 As String, lFecha2 As String
lFecha1 = InputBox("Ofertes des de")
lFecha2 = InputBox("Ofertes fins")
'Borrar contenido
ActiveSheet.Range("A3:G100").Clear
ActiveSheet.Range("H3:K100").Clear
'Ir a offers y desactivar filtro
Workbooks.Open Filename:="S:\Comercial\Offers.xlsx"
Workbooks("Offers").Activate
Sheets("Active").Select
With Workbooks("Offers").Sheets("Active")
If .AutoFilterMode = True Then .AutoFilterMode = False
End With
'Filtrar en active
Sheets("Active").Range("A3").AutoFilter Field:=22, Criteria1:=">=" & lFecha1, _
Operator:=xlAnd, Criteria2:="<=" & lFecha2
'Seleccionar Precio y copiar
Range("A3").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Range("AJ3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Report").Activate
Sheets("Report").Select
Range("F3").PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Seleccionar Percent Margen y copiar
Workbooks("Offers").Activate
Sheets("Active").Select
Range("A3").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Range("AM3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Report").Activate
Sheets("Report").Select
Range("G3").PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Seleccionar Responsable y copiar
Workbooks("Offers").Activate
Sheets("Active").Select
Range("A3").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Range("I3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Report").Activate
Sheets("Report").Select
Range("A3").Select
ActiveSheet.Paste
Application.CutCopyMode = False
'Seleccionar Ref. y copiar
Workbooks("Offers").Activate
Sheets("Active").Select
Range("A3").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Range("E3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Report").Activate
Sheets("Report").Select
Range("B3").PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Seleccionar Customer y copiar
Workbooks("Offers").Activate
Sheets("Active").Select
Range("A3").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Range("O3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Report").Activate
Sheets("Report").Select
Range("C3").PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Seleccionar Country y copiar
Workbooks("Offers").Activate
Sheets("Active").Select
Range("A3").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Range("Q3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Report").Activate
Sheets("Report").Select
Range("D3").PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Seleccionar Type y copiar
Workbooks("Offers").Activate
Sheets("Active").Select
Range("A3").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Range("K3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Report").Activate
Sheets("Report").Select
Range("E3").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Workbooks("Offers").Activate
Sheets("Active").Select
With Workbooks("Offers").Sheets("Active")
If .AutoFilterMode = True Then .AutoFilterMode = False
End With
End Sub