Anónimo
Macro para enviar archivo Excel por Correo Predetermin
Tengo diseñada una Macro que me envia una solo hoja de un libro de excel en forma automatica a una direccion de correo preestablecido a traves del Outlook. Pero ahora estoy nesecitando que la macro me reconosca no el Outloolk sino el programa de correo predeterminado que tenga la PC cualquiera fuese y que la direcion de correo a donde se envie la hoja Excel no este predeterminada sino que la pueda carar el usuario en ese momento.
1 respuesta
Respuesta de paramisolo
1
1
paramisolo, Desconozco temas financieros
Prueba a poner esta linea de codigo, para que se abra el programa de correo predeterminado y se añadirá como archivo adjunto el Libro, si quieres modifica tú para enviar solo la hoja que elijas, y que el usuario ponga la direccion de correo que le interese y el texto.
Application.Dialogs(xlDialogSendMail).Show
>Un saludo
>Julio
Si te ha servido y no necesitas nada más puntua y finaliza la consulta.
Application.Dialogs(xlDialogSendMail).Show
>Un saludo
>Julio
Si te ha servido y no necesitas nada más puntua y finaliza la consulta.
Amigo Julio desde ya muchas gracias por tu respuesta te cuento que estuve intentanto introduccir la linea de comando en mi macro perono obtengolo buscado
te paso cual es mi macro ya que no soy muy bueno explicando.
Lo abajo copiado me envia a traves de Microsoft Outlook a una direccion de correo preestablecida una hoja determinada de un archivo que contiene varias hojas y me copia en el cuerpo del email el contenido de esa hoja en un formato simil al .txt
Ahora lo que yo quiero es que haga lo mismo pero NO con el Microsoft Outlook, sino con el programa de correo electronico que tenga cualquier CPU donde se trabaje este archivo Excel y que le permita al usuario colocar cualquier direccion de correo electronico y NO una predeterminada.
Saludos y nuevamente gracias por vuestra atencion
Sub Mail_ActiveSheet()
'
' Mail_ActiveSheet Macro
' Macro grabada el 05/06/2009 por (xxxxxx)
' Working in 97-2007
'
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
Dim sTomador As String
Dim sLocalidad As String
Dim sCP As String
Dim sIva As String
Dim sUso As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sourcewb = ActiveWorkbook
sTomador = Hoja19.Cells(4, 2)
sLocalidad = Hoja19.Cells(5, 2)
sCP = Hoja19.Cells(6, 2)
sIva = Hoja19.Cells(7, 2)
sUso = Hoja19.Cells(8, 2)
With objMail
.To = "(xxxxxx)" ' cambia al destinatario de correo que desees
.Subject = "Solicitud de Cotizacion Nº"
.Body = "Solicitud de cotizacion: " & vbCrLf & "Tomador: " & sTomador & vbCrLf & "Localidad:" & sLocalidad & vbCrLf & "CP:" & sCP & vbCrLf & "Iva:" & sIva & vbCrLf & "Uso:" & sUso
End With
'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook
'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007, we exit the sub when your answer is
'NO in the security dialog that you only see when you copy
'an sheet from a xlsm file with macro's disabled.
If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With
' 'Change all cells in the worksheet to values if you want
' With Destwb.Sheets(1).UsedRange
' .Cells.Copy
' .Cells.PasteSpecial xlPasteValues
' .Cells(1).Select
' End With
' Application.CutCopyMode = False
'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = Sourcewb.Name & " " _
& Format(Now, "dd-mmm-yy h-mm-ss")
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
' .SendMail "(xxxxxx)", _
' "Solicitud de Cotizacion - Nº"
With objMail
.Attachments.Add Destwb.FullName
' .Display 'muestra mensaje
.Send
End With
On Error GoTo 0
.Close SaveChanges:=False
End With
Set objMail = Nothing
Set objOL = Nothing
'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Hoja19.Range(Hoja19.Cells(4, 2), Hoja19.Cells(19, 2)) = ""
Hoja19.Range(Hoja19.Cells(23, 1), Hoja19.Cells(26, 3)) = ""
Hoja19.Range(Hoja19.Cells(27, 2), Hoja19.Cells(29, 2)) = ""
MsgBox "Su Solicitud fue prosesada con éxito a la brevedad recibirá la respuesta a su casilla de e-mail"
End Sub
te paso cual es mi macro ya que no soy muy bueno explicando.
Lo abajo copiado me envia a traves de Microsoft Outlook a una direccion de correo preestablecida una hoja determinada de un archivo que contiene varias hojas y me copia en el cuerpo del email el contenido de esa hoja en un formato simil al .txt
Ahora lo que yo quiero es que haga lo mismo pero NO con el Microsoft Outlook, sino con el programa de correo electronico que tenga cualquier CPU donde se trabaje este archivo Excel y que le permita al usuario colocar cualquier direccion de correo electronico y NO una predeterminada.
Saludos y nuevamente gracias por vuestra atencion
Sub Mail_ActiveSheet()
'
' Mail_ActiveSheet Macro
' Macro grabada el 05/06/2009 por (xxxxxx)
' Working in 97-2007
'
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
Dim sTomador As String
Dim sLocalidad As String
Dim sCP As String
Dim sIva As String
Dim sUso As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sourcewb = ActiveWorkbook
sTomador = Hoja19.Cells(4, 2)
sLocalidad = Hoja19.Cells(5, 2)
sCP = Hoja19.Cells(6, 2)
sIva = Hoja19.Cells(7, 2)
sUso = Hoja19.Cells(8, 2)
With objMail
.To = "(xxxxxx)" ' cambia al destinatario de correo que desees
.Subject = "Solicitud de Cotizacion Nº"
.Body = "Solicitud de cotizacion: " & vbCrLf & "Tomador: " & sTomador & vbCrLf & "Localidad:" & sLocalidad & vbCrLf & "CP:" & sCP & vbCrLf & "Iva:" & sIva & vbCrLf & "Uso:" & sUso
End With
'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook
'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007, we exit the sub when your answer is
'NO in the security dialog that you only see when you copy
'an sheet from a xlsm file with macro's disabled.
If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With
' 'Change all cells in the worksheet to values if you want
' With Destwb.Sheets(1).UsedRange
' .Cells.Copy
' .Cells.PasteSpecial xlPasteValues
' .Cells(1).Select
' End With
' Application.CutCopyMode = False
'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = Sourcewb.Name & " " _
& Format(Now, "dd-mmm-yy h-mm-ss")
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
' .SendMail "(xxxxxx)", _
' "Solicitud de Cotizacion - Nº"
With objMail
.Attachments.Add Destwb.FullName
' .Display 'muestra mensaje
.Send
End With
On Error GoTo 0
.Close SaveChanges:=False
End With
Set objMail = Nothing
Set objOL = Nothing
'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Hoja19.Range(Hoja19.Cells(4, 2), Hoja19.Cells(19, 2)) = ""
Hoja19.Range(Hoja19.Cells(23, 1), Hoja19.Cells(26, 3)) = ""
Hoja19.Range(Hoja19.Cells(27, 2), Hoja19.Cells(29, 2)) = ""
MsgBox "Su Solicitud fue prosesada con éxito a la brevedad recibirá la respuesta a su casilla de e-mail"
End Sub
Efectivamente entendí que en cada pc los usuarios utilizan un gestor de correo y lo que hace la linea de codigo es iniciar la aplicación predeterminada que tenga cada PC por ello debes de quitar las lineas que hacen referencia a Outlook tanto variables como inicios de la aplicación. El resto Cuerpo del mensaje, destinatario, remitente... etc todo es igual arma tu macro como te digo y pruebala instala otro gestor de correo y marcaló como predeterminado, y la ejecutas, iras viendo que linea de codigo te queda por modificar para que te envíe correctamente la hoja al cuerpo del mensaje.
Si tan solo pones en la macro mi linea de codigo se arranca la aplicación predeterminada de correo, que en tu caso será Outlook pero si otro usuario tiene por ejemplo Mozilla Thunderbird (como es mi caso) pues esa es la que se iniciará. El resto de codigo es el mismo.
>Un saludo
>Julio
PD si necesitas alguna aclaracion mas me lo dices
Si tan solo pones en la macro mi linea de codigo se arranca la aplicación predeterminada de correo, que en tu caso será Outlook pero si otro usuario tiene por ejemplo Mozilla Thunderbird (como es mi caso) pues esa es la que se iniciará. El resto de codigo es el mismo.
>Un saludo
>Julio
PD si necesitas alguna aclaracion mas me lo dices
Estimado Julio e quitado tal tu me lo mensionas las siguientes lineas que se referencian al programa predeterminado Oultook
linea quitada **Dim objOL As New Outlook.Application
linea quitada **Set objOL = New Outlook.Application
y lo que sucede es que empieza a arrojarme una serie de errores en muchas lineas mas los cuales superan mis conocimientos.
Sabrias mencionarmen puntualmente cuales de las filas de mi progrmacion tendria que modificar ????
Saludos
linea quitada **Dim objOL As New Outlook.Application
linea quitada **Set objOL = New Outlook.Application
y lo que sucede es que empieza a arrojarme una serie de errores en muchas lineas mas los cuales superan mis conocimientos.
Sabrias mencionarmen puntualmente cuales de las filas de mi progrmacion tendria que modificar ????
Saludos
Esta macro la copiastes y la pegaste desde esta página:
http://www.rondebruin.nl/mail/folder1/mail2.htm
Pues en la misma página está la forma de utilizar la aplicación que el usuario tenga predeterminada sea Outlook u otra, aquí te la dejo:
Sub Mail_ActiveSheet()
'Working in 97-2007
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sourcewb = ActiveWorkbook
'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook
'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007, we exit the sub when your answer is
'NO in the security dialog that you only see when you copy
'an sheet from a xlsm file with macro's disabled.
If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With
' 'Change all cells in the worksheet to values if you want
' With Destwb.Sheets(1).UsedRange
' .Cells.Copy
' .Cells.PasteSpecial xlPasteValues
' .Cells(1).Select
' End With
' Application.CutCopyMode = False
'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = "Part of " & Sourcewb.Name & " " _
& Format(Now, "dd-mmm-yy h-mm-ss")
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
.SendMail "[email protected]", _
"This is the Subject line"
On Error GoTo 0
.Close SaveChanges:=False
End With
'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
>Un saludo
>Julio
http://www.rondebruin.nl/mail/folder1/mail2.htm
Pues en la misma página está la forma de utilizar la aplicación que el usuario tenga predeterminada sea Outlook u otra, aquí te la dejo:
Sub Mail_ActiveSheet()
'Working in 97-2007
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sourcewb = ActiveWorkbook
'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook
'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007, we exit the sub when your answer is
'NO in the security dialog that you only see when you copy
'an sheet from a xlsm file with macro's disabled.
If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With
' 'Change all cells in the worksheet to values if you want
' With Destwb.Sheets(1).UsedRange
' .Cells.Copy
' .Cells.PasteSpecial xlPasteValues
' .Cells(1).Select
' End With
' Application.CutCopyMode = False
'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = "Part of " & Sourcewb.Name & " " _
& Format(Now, "dd-mmm-yy h-mm-ss")
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
.SendMail "[email protected]", _
"This is the Subject line"
On Error GoTo 0
.Close SaveChanges:=False
End With
'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
>Un saludo
>Julio
En muchos casos la respuesta es la correcta pero seria altamente positivo dar ejemplos de las aclaraciones en forma mas coloquial.
Des toas formas muchas gracias.
Des toas formas muchas gracias.
- Compartir respuesta
- Anónimo
ahora mismo