Link to home
Create AccountLog in
Avatar of bsncp
bsncpFlag for Afghanistan

asked on

VB email distribution list with space in name

Our Outlook administrator created a company distribution list that has a space in the name.  I can't change it.  So I need my code to be able to see there is a space.  Currently, the code below errors out becuase it doesn't recognize there is a space between the words" School" and "Outbound".  I need to modify the code to reflect the space.

Function TimeReport()

Set EmailApp = CreateObject("Outlook.Application")
Set NameSpace = EmailApp.GetNamespace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)

' send the created file from above now
EmailSend.To = "$School Division@sportsupplygroup.com" & _
EmailSend.Subject = "Time Tracking Report"
EmailSend.HTMLBody = "<a href=\\ssgvrtf4\sapshared\Sales_Dept\Reports\Rep\RepDaily.xls>Sales Rep Activity Tracking (Click Here)</a></br></br></a></br></br> This report is a detailed activity report for each rep for the previous day." & _
"<br><br><br><br><br><br><br><br><br><br><br><br>" & strReportMsg
EmailSend.Send

End Function

Open in new window

Avatar of Alan Gunn
Alan Gunn
Flag of United Kingdom of Great Britain and Northern Ireland image

Line 8 appears to end with a "& _" continuation.

Does the DL have a $ at the start othe name?

I tried the code below and it sent an email to a DL I created called "School Division"

TimeReport()

Function TimeReport()

Set EmailApp = CreateObject("Outlook.Application")
Set NameSpace = EmailApp.GetNamespace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)
strtimereport = "this is the report"
' send the created file from above now
'EmailSend.To = "$School Division@sportsupplygroup.com" & _
emailsend.to = "School Division"
EmailSend.Subject = "Time Tracking Report"
EmailSend.HTMLBody = "<a href=\\ssgvrtf4\sapshared\Sales_Dept\Reports\Rep\RepDaily.xls>Sales Rep Activity Tracking (Click Here)</a></br></br></a></br></br> This report is a detailed activity report for each rep for the previous day." & _
"<br><br><br><br><br><br><br><br><br><br><br><br>" & strReportMsg
EmailSend.Send

End Function 

Open in new window

Avatar of bsncp

ASKER

My fault...I did fail to remove the "& _" continuation.   Sorry...this one distribution list is actually one of several I am sending to.  To simplify my post, I tried to limit it to just the distribution list with which I was having the problem...but forgot to remove that continuation.  Removing the coninuation does not resolve the issue.  Yes...the "$" is at the beginning of the distribbution list's name.  the admin did that so it would appear first alphabetically when searching distribnution lists.  Could the dollar sign character be a factor here?
Avatar of RobSampson
Hi, just a guess, what if you put the brackets around it?

EmailSend.To = "<$School Division@sportsupplygroup.com>"

Or
EmailSend.To = "<""$School Division@sportsupplygroup.com"">"

Or
EmailSend.To = """$School Division""@sportsupplygroup.com"

Or, probably less likely to work
EmailSend.To = "$School%20Division@sportsupplygroup.com"

Regards,

Rob.
ASKER CERTIFIED SOLUTION
Avatar of bsncp
bsncp
Flag of Afghanistan image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
OK sure.  That makes things easier.  I've read conflicting things about whether you can have spaces or not, and people have suggested that some of the above methods work.

Anyway, glad you sorted it out.

Regards,

Rob.
Avatar of bsncp

ASKER

Solved it myself...can have a space in the name of a distribution list, but can't have a space in the actual email address behind it.