Hice un pequeño sub en excel que envía un correo electrónico según los parámetros que ingresas:
Sub Mail_LSP(mailsubject As String, consignee As String, coalcopy As String, mailbody As String)
Dim mlook As Outlook.MailItem
Set mlook = Outlook.Application.CreateItem(olMailItem)
mySubject = mailsubject
mlook.To = consignee
mlook.CC = coalcopy
mlook.Subject = mailsubject
mlook.Body = mailbody
mlook.Send
End Sub
Quiero mejorar el parámetro del cuerpo del correo. ¿Hay alguna forma de asignar el contenido de un archivo .txt a una variable, para poder usar esta variable como parámetro de mi procedimiento?
Respuesta1
Intentar FileSystemObject
:
Private Sub CommandButton1_Click()
Set fso = CreateObject("Scripting.FileSystemObject")
Path = Range("E3")
Set filestream = fso.OpenTextFile(Path, 1)
contents = filestream.ReadAll()
Range("F4") = contents
End Sub
Respuesta2
Encontré una manera usando: Open mailbody For Input As #1
y luegoLine Input #1
Sub Mail_LSP(mailsubject As String, consignee As String, coalcopy As String, mailbody As String)
Dim mlook As Outlook.MailItem
Dim linecontent As String
Dim mailcontent As String
Open mailbody For Input As #1
Do Until EOF(1)
Line Input #1, linecontent
mailcontent = mailcontent & vbNewLine & linecontent & vbNewLine
Loop
Close #1
Set mlook = Outlook.Application.CreateItem(olMailItem)
mySubject = mailsubject
mlook.To = consignee
mlook.CC = coalcopy
mlook.Subject = mailsubject
mlook.Body = mailcontent
mlook.Send
End Sub