입력한 매개변수에 따라 이메일을 보내는 작은 하위 항목을 Excel로 만들었습니다.
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
mailbody 매개변수를 개선하고 싶습니다. .txt 파일의 내용을 변수에 할당하여 이 변수를 내 프로시저의 매개변수로 사용할 수 있는 방법이 있습니까?
답변1
노력하다 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
답변2
Open mailbody For Input As #1
다음을 사용하여 방법을 찾았습니다.Line 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