Save file as .msg instead of .txt

jsmith2094

New Member
Joined
Aug 19, 2021
Messages
35
Office Version
  1. 365
Platform
  1. 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 ?

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
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi,

I'm using this solution :

Add a row on top of the tab.
Enter a description for each column. For example, if the first column contains the names of the contacts, and the second column contains the email addresses for the contacts, enter "Name" into A1 and "E-mail Addresses" into B1.
Save the excel sheet as a CSV file.

In outlook, you can use the import wizard ('File', 'Open&Export', 'Import/export', 'from other program/file', 'CSV') to dd the contect to the Address book/contacts.

regards,

Martin
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top