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
Buenas gente, esot y programando una macro la cual al llegar a la sentencia :
Cells(2, columna).Activate
me tira: se ha producido el error 1004 en tiempo de ejecucion: error definido por la aplicacion o el objeto
me seria de gran ayuda si identifican la causa del mismos. el codigo completo es el siguiente:
Dim f As String
Dim contadorhija As String
copiado = 0
columna = 3
contadorpadre = 3
Windows("Herramienta Patricio.xlsm").Activate
Cells(3, 1).Select
'ciclo recorredor de padres
Do Until IsEmpty(ActiveCell.Value)
ref = ActiveCell
Set Fso = CreateObject("Scripting.FileSystemObject")
'suspende macro se falta una estructura
If Not (Fso.FileExists("G:\VLS-Industrial\Logistica\PReid\Consumo MP sem siguiente\Estructuras\" & ref & ".xls")) Then
MsgBox "La estructura de la referencia " & ref & " no fue bajada de sap, descarguela, y vuelva a correr la macro"
Exit Sub
End If
'abre estructura
Workbooks.Open Filename:= _
"G:\VLS-Industrial\Logistica\PReid\Consumo MP sem siguiente\Estructuras\" & ref & ".xls"
Windows(ref & ".xls").Activate
Range("E11").Activate
contadorhija = 11
columna = 3
'recorro estructura y va armandola en el hoja de excel, selecciona ref hija y comprueba
Do Until IsEmpty(ActiveCell.Value)
Windows(ref & ".xls").Activate
Cells(contadorhija, 5).Activate
refhhija = ActiveCell
'Comprueba si existe ref hija en tabla
Windows("Herramienta Patricio.xlsm").Activate
Cells(2, columna).Activate
Do Until IsEmpty(ActiveCell.Value) Or copiado = 1
'Comprueba si existe ref hija en tabla
If refhija = ActiveCell Then
Windows(ref & ".xls").Activate
ActiveCell.Offset(0, 4).Activate
Selection.Copy
Windows("Herramienta Patricio.xlsm").Activate
Cells("contadorpadre", columna + 1).Select
ActiveSheet.Paste
activecells.Offset(0, 1).Activate
activecells = Cells("contadorpadre", 2) * Cells("contadorpadre", columna + 1)
activerange.Offset(0, 1).Activate
contadorhija = contadorhija + 1
contadorpadre = contadorpadre + 1
copiado = 1
End If
Windows("Herramienta Patricio.xlsm").Activate
facha = columna + 3
Cells(2, columna).Activate
Loop
Windows(ref & ".xls").Activate
Cells(contadorhija, 14).Activate
If ActiveCell = "COMP" Or copiado = 0 Then
Cells(contadorhija, 5).Activate
Selection.Copy
Windows("Herramienta Patricio.xlsm").Activate
ActiveSheet.Paste
Windows(ref & ".xls").Activate
Cells(contadorhija, 9).Activate
Selection.Copy
Windows("Herramienta Patricio.xlsm").Activate
Cells("contadorpadre", columna + 1).Activate
ActiveSheet.Paste
Cells("contadorpadre", columna + 2) = Cells("contadorpadre", columna + 1) * Cells("facha", 2)
End If
Loop
Windows("Herramienta Patricio.xlsm").Activate
fila.Value = fila.Value + 1
Cells(1, fila).Select
Loop
End Sub