Como corregir macro excel que envía mail de rango y adjunto?
Tengo una macro que me permite enviar selección de hoja de Excel. Funcionaba perfectamente hasta que le agregue la línea para seleccionar el archivo adjunto. Allí detiene la ejecución y dice “Error de automatización”. Desde ya muchas gracias por tu valiosa ayuda.
Este es la Macro:
Sub
Sub Enviar_Rango_a_Destinatario_de_correo()
'Seleccionamos el rango de celdas a enviar Select
ActiveSheet.Range("A1:m27").Select
' Show the envelope on the ActiveWorkbook.
ActiveWorkbook.EnvelopeVisible = True
'Llamamos al envío...
With ActiveSheet.MailEnvelope
.Item.To = ThisWorkbook.Sheets("Formulario (Envio)").Range("Q2").Value
.Item.cc = ThisWorkbook.Sheets("Formulario (Envio)").Range("R2").Value
'con copia a...
.Item.Subject = ThisWorkbook.Sheets("Formulario (Envio)").Range("P3").Value
' Llamamos al atachment . ".Item.Attachments = (ruta_archivo)"
.Item.Send
End With
End Sub
Sub selec_archivo()
On Error GoTo a2
ruta_archivo = Application.GetOpenFilename(Title:="Click para Seleccionar Archivo a Enviar")
If ruta_archivo = False Then
Exit Sub
Else
Cells(7, 16).Value = ruta_archivo
End If
a2:
End Sub
()
'Seleccionamos el rango de celdas a enviar Select
ActiveSheet.Range("A1:m27").Select
' Show the envelope on the ActiveWorkbook.
ActiveWorkbook.EnvelopeVisible = True
'Llamamos al envío...
With ActiveSheet.MailEnvelope
.Item.To = ThisWorkbook.Sheets("Formulario (Envio)").Range("Q2").Value
.Item.cc = ThisWorkbook.Sheets("Formulario (Envio)").Range("R2").Value
'con copia a...
.Item.Subject = ThisWorkbook.Sheets("Formulario (Envio)").Range("P3").Value
.Item.Attachments.Add (ruta_archivo)
' Llamamos al atachment de este modo y se detiene la ejecución. Dice error de automatización"
.Item.Send
End With
End Sub
Sub selec_archivo()
On Error GoTo a2
ruta_archivo = Application.GetOpenFilename(Title:="Click para Seleccionar Archivo a Enviar")
If ruta_archivo = False Then
Exit Sub
Else
Cells(7, 16).Value = ruta_archivo
End If
a2:
End Sub