Ich habe in Excel ein kleines Subskriptionstool erstellt, das eine E-Mail entsprechend den von Ihnen eingegebenen Parametern versendet:
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
Ich möchte den Mailbody-Parameter verbessern. Gibt es eine Möglichkeit, den Inhalt einer TXT-Datei einer Variablen zuzuweisen, sodass ich diese Variable dann als Parameter für meine Prozedur verwenden kann?
Antwort1
Versuchen 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
Antwort2
Habe einen Weg gefunden mit: Open mailbody For Input As #1
und dannLine 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