Extracting recipient name from File name

G

Guest

Hi,

We currently have a huge number of files which are sent out each month. The
e-mail content is the same but the file attached is different for each
recipient.

The file name contains the recipients name after a _ character.

Therefore is there a way of having a e-mail and once the attachment is added
the recipient name is automatically produced from the details in the
attachment from clicking a button on the toolbar?

Thanks for any help you can provide.
 
M

Michael Bauer [MVP - Outlook]

You can access the attachments via the MailItem's Attachments property; e.g.
the first one would be Attachments(1). That returns an Attachment object,
which has a FileName property.

Parse that FileName with the InStr function. It tells you the position of
the "_" character. Then use the Right function to get what's right of a
given position.

All properties and functions are explained in detail in the VBA help.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Fri, 22 Jun 2007 04:20:01 -0700 schrieb Russell:
 
G

Guest

Hi,

Many thanks for your reply but I can not find exactly what you are
explaining to do.

Is it possible you could write an example of the code I need to use in order
that I can "tweek" this to our satisfaction.

Also, you have broken this down into 3 seperate tasks. Therefore will this
need to be written as 3 seperate macro's to be run from the composed mail
item?

Thanks again for your help.
 
M

Michael Bauer [MVP - Outlook]

The basics could look like this. I'd suggest to create a new toolbar button
(right click the toolbar, customize, commands, macro, drag the public
method's name to the toolbar).

Private WithEvents m_Mail as Outlook.MailItem

Public Sub StartMacro()
Set m_Mail = Application.CreateItem(olMail)
m_Mail.Display
End Sub

Private m_Mail_AttachmentAdd(Attachment as Attachment)
Dim pos&
Dim Text$

pos=Instr(Attachment.FileName, "_")

' now the variable pos contains the start position of the searched
character (or 0 if not found).
' please continue yourself: Use the Right function to write the searched
recipient's name into the variable Text
' then add that name via m_Mail.Recipients.Add
End Sub

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 26 Jun 2007 04:24:00 -0700 schrieb Russell:
 

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