Como agregar mas destinatarios a esta instruccion

Solicito tu apoyo para que me indiques como agregar mas destinatarios en la siguiente macro ya que solo me recibe uno y tambien para saber por que al momento de correrla me inhabilita la otra macro que tengo en el libro??
Sub Mail_ActiveSheet()
' Works in Excel 97 through Excel 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
' Using ActiveSheet.Copy creates a new workbook with
' the sheet and the file format is the same as the
' original workbook.
' Copy the worksheet 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 are using Excel 97-2003.
FileExtStr = ".xls": FileFormatNum = -4143
Else
' You are using Excel 2007.
' When you use ActiveSheet.Copy to create a workbook,
' you are prompted with a security dialog. If you click No
' in the dialog, then the name of Sourcewb is the same
' as Destwb and you exit the subroutine. You only see this
' dialog when you attempt to copy a worksheet from an .xlsm file with macros 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
' Code 51 represents the enumeration for a macro-free
' Excel 2007 Workbook (.xlsx).
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
' Code 52 represents the enumeration for a
' macro-enabled Excel 2007 Workbook (.xlsm).
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
' Code 56 represents the enumeration for a
' a legacy Excel 97-2003 Workbook (.xls).
Case 56: FileExtStr = ".xls": FileFormatNum = 56
' Code 50 represents the enumeration for a
' binary Excel 2007 Workbook (.xlsb).
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With
' Change all cells in the worksheet to values, if desired.
'' With Destwb.Sheets(1).UsedRange
'' .Cells.Copy
'' .Cells.PasteSpecial xlPasteValues
'' .Cells(1).Select
'' End With
''Application.CutCopyMode = False
'Save the new workbook and then mail 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]", _
"Mensaje de Prueba."
On Error GoTo 0
.Close SaveChanges:=True
End With
End Sub

1 Respuesta

Respuesta
1
Dices ¿No puedes agregar más de un destinatario?
Pregunta1: ¿De dónde tomas los destinatarios?
Pregunta2: ¿Ya probaste agregando al final los renglones siguientes?
-
With Application
.ScreenUpdating = true
.EnableEvents = true
End With
-
En esta instruccion agrego los destinatarios pero no se de que manera agregar mas,
On Error Resume Next
.SendMail "[email protected]", _
"Mensaje de Prueba."
En este caso, la solución podría ser esta:
-
. SendMail "Per1@mailserver.com,Per2@mailserver.com,etc@mailserver.com,", _
"Mensaje de Prueba."
-
Este método, aunque programado, es fijo. Pensé que se los asignabas dinámicamente, es decir, que los tomabas de algún rango.
Introduje la cadena de texto en la funcion .SendMail tal como me lo indicaste
.SendMail "[email protected],[email protected],[email protected],", _
pero no envia el mail, solo lo hace cuando dejo un solo destinatario, hice pruebas con ; y tampoco lo envia.
Saludos.
Agrega el siguiente DIM en donde están los demás DIM's
DIM Usuarios(10) as string
-
El 10 cámbialo por el número de destinatarios que necesites.
-
Agrega los destinatarios de la siguiente manera:
-
Usuario (1) = "[email protected]"
Usuario (2) = "[email protected]"
Usuario (3) = "[email protected]"
Usuario (4) = "[email protected]"
-
Modifica
-
.SendMail Recipients:=Usuarios, Subject:="Mensaje de Prueba"
-
Gracias, una ultima pregunta, en que parte del codigo agrego los destinatarios
Saludos.
una linea antes del .SendMail
-
En este punto; puedes dejarlos estáticos, como están, o teclearlos en algún lugar de tu libro. Si elijes esta última opción, el código quedaría algo así como lo siguiente:
-
Usuario(1)=Sheets(Hoja1).Range("A1").Value
Usuario(2)=Sheets(Hoja1).Range("A2").Value
Usuario(3)=Sheets(Hoja1).Range("A3").Value
Usuario(4)=Sheets(Hoja1).Range("A4").Value
-
Para lo cual, tendrás que agregar a tus usuarios en A1 de Hoja1, o adáptalo a la estructura de datos de tu libro.
-
buen dia, me inclino mas por la opcion de dejarlos estaticos en el codigo, ya introduje los usuarios como me dijiste mas me envia un error de compilacion el mensaje dice no se ha definido sub o funcion y me manda el cursor al primer usuario.
disculpa la molestia, saludos.
Trae aqui tu código...
Te envio el codigo. Saludos.
Sub Mail_ActiveSheet()
' Works in Excel 97 through Excel 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 Usuarios(4) As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sourcewb = ActiveWorkbook
' Using ActiveSheet.Copy creates a new workbook with
' the sheet and the file format is the same as the
' original workbook.
' Copy the worksheet 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 are using Excel 97-2003.
FileExtStr = ".xls": FileFormatNum = -4143
Else
' You are using Excel 2007.
' When you use ActiveSheet.Copy to create a workbook,
' you are prompted with a security dialog. If you click No
' in the dialog, then the name of Sourcewb is the same
' as Destwb and you exit the subroutine. You only see this
' dialog when you attempt to copy a worksheet from an .xlsm file with macros 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
' Code 51 represents the enumeration for a macro-free
' Excel 2007 Workbook (.xlsx).
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
' Code 52 represents the enumeration for a
' macro-enabled Excel 2007 Workbook (.xlsm).
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
' Code 56 represents the enumeration for a
' a legacy Excel 97-2003 Workbook (.xls).
Case 56: FileExtStr = ".xls": FileFormatNum = 56
' Code 50 represents the enumeration for a
' binary Excel 2007 Workbook (.xlsb).
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With
' Change all cells in the worksheet to values, if desired.
'' With Destwb.Sheets(1).UsedRange
'' .Cells.Copy
'' .Cells.PasteSpecial xlPasteValues
'' .Cells(1).Select
'' End With
''Application.CutCopyMode = False
'Save the new workbook and then mail 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
Usuario(1) = "[email protected]"
Usuario(2) = "[email protected]"
Usuario(3) = "[email protected]"
Usuario(4) = "[email protected]"
.SendMail Recipients:=Usuarios, Subject:="Mensaje de Prueba"
On Error GoTo 0
.Close SaveChanges:=True
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
vaya... es cierto, hay un error mio.
-
Sí, el error lo produce .sendmail, porque envía a usuarios y estos no están definidos, porque te pase un código incorrecto.
-
Dice:
Usuario(1) = "[email protected]"
Usuario(2) = "[email protected]"
Usuario(3) = "[email protected]"
Usuario(4) = "[email protected]"
-
Debe decir:
Usuarios(1) = "[email protected]"
Usuarios(2) = "[email protected]"
Usuarios(3) = "[email protected]"
Usuarios(4) = "[email protected]
-
Ya con esto... debe funcionar.
-

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas