A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Attach documents to mail merged emails based on merge fields



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 20th 07, 12:03 PM posted to microsoft.public.outlook.program_vba
bony_tony
external usenet poster
 
Posts: 5
Default Attach documents to mail merged emails based on merge fields

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/mic...7f64afc62bd773

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

Ads
  #2  
Old June 20th 07, 12:52 PM posted to microsoft.public.outlook.program_vba
bony_tony
external usenet poster
 
Posts: 5
Default Attach documents to mail merged emails based on merge fields

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

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail Merge User-Defined Fields David E Outlook - Using Forms 4 October 5th 06 12:07 AM
How to direct output from Word mail merge to multiple Word documents [email protected] Outlook - General Queries 3 August 11th 06 05:10 AM
Attach Mail Merge Letter to Contacts Patti Outlook - Using Contacts 1 July 29th 06 12:41 AM
Mail Merge from Outlook opens up two MS Word documents. [email protected] Outlook - General Queries 10 July 6th 06 10:44 PM
re. Can't attach photos or Word documents to email mike carrington Outlook - General Queries 3 May 3rd 06 05:05 PM


All times are GMT +1. The time now is 05:02 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.