Attach documents to mail merged emails based on merge fields

B

bony_tony

Hi,
I'm new to VBA in outlook, although I have used it in Excel

I have read this thread;

http://groups.google.co.uk/group/mi...s+to+mail+merge&rnum=2&hl=en#0c7f64afc62bd773

I now have emails in my outbox, which I would like to attach files to.

However, I want to attach different Excel files to the different
messages, depending on which account reference (insterted from a merge
field) the message is relating to.
It looks like the merge fields have been replaced with text on the
emails, so I would somehow like to attach different files to the
emails based on the references found after "Account " on the first
line;

ie I would like to attach, say C:/REF12345.xls to the first message,
which would have the following in it's body

Account REF12345

Balance 13,024.88

Regards
A Company

The account reference is sometimes a different length of characters.

I'm assuming the following code would do this, but how do I apply my
reference to the value 'x'?

Sub AddAttachmentToSelectedMessages()
Dim objItem As Object
If ActiveExplorer.Selection.Count = 0 Then Exit Sub

For Each objItem In ActiveExplorer.Selection
objItem.Attachments.Add ("C:\" & x & ".xls")
objItem.Save
objItem.Send
Next
End Sub

Regards
Tony
 
B

bony_tony

It's ok, don't worry, found a function some outlook genius posted ;-)

Function ParseTextLinePair(strSource As String, strLabel As String)
Dim intLocLabel As Integer
Dim intLocCRLF As Integer
Dim intLenLabel As Integer
Dim strText As String

' locate the label in the source text
intLocLabel = InStr(strSource, strLabel)
intLenLabel = Len(strLabel)
If intLocLabel > 0 Then
intLocCRLF = InStr(intLocLabel, strSource, vbCrLf)
If intLocCRLF > 0 Then
intLocLabel = intLocLabel + intLenLabel
strText = Mid(strSource, _
intLocLabel, _
intLocCRLF - intLocLabel)
Else
intLocLabel = Mid(strSource, intLocLabel + intLenLabel)
End If
End If
ParseTextLinePair = Trim(strText)
End Function
 

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