Creating a distribution list

K

Kerstin Schiebel

Hi,

I use sometimes a little script for importing a text file for creating a
distribution list.
The syntax for the text file is email;name
I get a DL where the display name is always the email address. Now
emailaddress = display name
I want to change the script that the name is always imported into the field
"display name".
I would be very lucky, if someone could give me a hint.

Thank you very much.
Kerstin
-----------------------
'Öffnen der Datei
Set f = fs.GetFile(Dateiname)
Set ts = f.OpenAsTextStream(ForReading, TristateFalse)


'The MailItem is required to create the Recipients collection
Set myMailItem = myOlApp.CreateItem(olMailItem)
Set myRecipients = myMailItem.Recipients

I = 1
'Lesen der einzelnen Datensätze und hinzufügen der EMail-Adressen
'ASCII-Datei in der Form: emailadresse; Name
While ts.AtEndOfStream <> True
zeile = ts.ReadLine
Pos = InStr(1, zeile, ";")
If Pos > 0 Then
EMailAdr = Mid(zeile, 1, Pos - 1)
myRecipients.Add EMailAdr
Else
MsgBox "Fehler in " & zeile
End If
Wend

'Create the Distribution List item
Set myDistList = myFolder.Items.Add(olDistributionListItem)
myDistList.DLName = InputBox("Bitte geben Sie den Namen der Liste ein: ",
, "???")

myDistList.AddMembers myRecipients
myDistList.Save
---------------------
 
M

Michael Bauer

Hi Kerstin,

please use this syntax or adding the Recipient:

myRecipients.Add "<" & Name & "> " & EMailAdr
 
K

Kerstin Schiebel

Hi Michael,

sorry for the late answer but my PC had some problems during the last days
:-(
First thank you very much for the hint.

Now I get always the Display Name "Outlook" instead of
Mustermann, E. (E.Mustermann@gmx)

A record in my text file looks like this:
(e-mail address removed); Mustermann, Elke ([email protected])

Do you have an idea?

Thanks
Kerstin
 
K

Kerstin Schiebel

Hi Michael,

....
'The MailItem is required to create the Recipients collection
Set myMailItem = myOlApp.CreateItem(olMailItem)
Set myRecipients = myMailItem.Recipients

I = 1
'Lesen der einzelnen Datensätze und hinzufügen der EMail-Adressen
'ASCII-Datei in der Form: emailadresse; Name
While ts.AtEndOfStream <> True
zeile = ts.ReadLine
Pos = InStr(1, zeile, ";")
If Pos > 0 Then
EMailAdr = Mid(zeile, 1, Pos - 1)
' myRecipients.Add EMailAdr
myRecipients.Add "<" & Name & "> " & EMailAdr

....

Thank you very much
Kerstin
 
M

Michael Bauer

Ok, you forgot to extract the name. If your records are reliably in the
described format then I´d do it this way:

Dim as() as String
as=Split(zeile, ";")
myRecipients.Add "<" & as(1) & "> " & as(0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top