PDA

View Full Version : Solved: Putting attachment filenames in a message body.



LearnFrench
10-14-2008, 02:48 PM
I'm not a programmer - I'm just using a script that I ran across somewhere on the Internet. I'm using Outlook 2003 on XP. So far this script renames the subject, adds a quick line to the body and then sends the message. I would like it to add the file names of the attachments (plural) to the body after my "inspirational message." Bonus: Can I point my current olItem.Body at a text file? Thanks so much for you help.



Sub ChangeSubject()

Set oActiveExplorer = Application.ActiveExplorer

MsgBox TypeName(oActiveExplorer.Selection)

Set oSelection = oActiveExplorer.Selection

For I = 1 To oSelection.Count

Set olItem = oSelection.Item(I)

olItem.Subject = "Your weekly inspirational message"

olItem.Body = "Inspirational Message"

olItem.Send

Next

End Sub

jfournier
10-15-2008, 06:03 AM
This is about how you'd go about doing what you want...

olItem.Body = "Inspirational Message"

Dim InspMsg as String

Dim InFilePath as String

InFilePath = "C:\test.txt"

Open InFilePath For Input As 1

Dim CurrLine as string
While Not eof( 1 )
Line Input #1, CurrLine
InspMsg = InspMsg & vbCr & CurrLine
Wend

Close #1

'Put in a few lines before attachment names
InspMsg = InspMsg & vbCr & vbCr

Dim CurrAttch as Attachment
For Each CurrAttch In olItem.Attachments
InspMsg = InspMsg & CurrAttach.FileName & vbCr
Next CurrAttch

olItem.Body = InspMsg

LearnFrench
10-15-2008, 09:59 PM
Thanks so much for you assistance - I really appreciate it!