jsmith2094
New Member
- Joined
- Aug 19, 2021
- Messages
- 35
- Office Version
- 365
- Platform
- Windows
HI,
I found some code online to save a list of email addresses as a TXT file but I want to save it as a .msg file so the mailing list can be added to outlook
I tried to change the extension as txt but when i try and open in outlook it says the file is corrupt
any ideas ?
I found some code online to save a list of email addresses as a TXT file but I want to save it as a .msg file so the mailing list can be added to outlook
I tried to change the extension as txt but when i try and open in outlook it says the file is corrupt
any ideas ?
VBA Code:
Public Sub Add_Semicolon_To_Email_Addresses_List()
Dim iRow As Double, iCol As Double, Ws As Worksheet
Dim Email_List As String, eFile_Path As String, eFile
'Initialize variables
iRow = 2
iCol = 1
Email_List = ""
eFile = FreeFile
Set Ws = ThisWorkbook.Sheets("Sheet1")
'Get Each Email Address and Add a Semicolon
While Ws.Cells(iRow, iCol) <> ""
Email_List = Email_List & Ws.Cells(iRow, iCol) & ";"
iRow = iRow + 1
Wend
If Email_List <> "" Then
'Trim the Last Semicolon
Email_List = VBA.Mid(Email_List, 1, VBA.Len(Email_List) - 1)
'Write Semicolon separated Email Address List to Output File
'Create Email List from Excel
eFile_Path = Ws.Cells(1, 3)
If eFile_Path = "" Then eFile_Path = ThisWorkbook.Path & "\Email_Distribution_List1.msg"
Open eFile_Path For Output As eFile
Print #eFile, Email_List
Close #eFile
MsgBox "Email List Added with Semicolon in this path " & eFile_Path
Exit Sub
End If
MsgBox "No Email Ids to Covert to Distribution List"
End Sub