VB: Putting filenames in a message body.
October 13, 2008 11:25 PM
Subscribe
VB Script Help: I would like to put the filenames of my attachments into the message body of my emails. How do I do that?
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?
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
posted by bigmusic to computers & internet (5 comments total)
Dim myAttachments As Attachments
Set myAttachments = myEmailObject.Attachments
' Skip shortcuts and embedded messages
Do While myAttachments(AttachmentsCounter).Type = olOLE _
Or Left$(myAttachments(AttachmentsCounter).DisplayName, 8) = "Shortcut" _
Or InStr(myAttachments(AttachmentsCounter).FileName, ".msg") > 0
AttachmentsCounter = AttachmentsCounter - 1
DO SOMETHING WITH THE ATTACHMENT NAME perhaps
myEmailObject.Body = myEmailObject.Body & vbCrLf & myAttachments(AttachmentsCounter).DisplayName
Loop
Now, if you want to load the entire body in from a file you could just read it in from the file thus:
Dim f as long
Dim myText as string
f = FreeFile
Open WHATEVERYOURPATHIS for input as f
myText = Input$(LOF(f), #f)
Close #f
myEmail.body = mytext
(Aircode so may not run first time but you get the idea..)
posted by NailsTheCat at 3:45 AM on October 14, 2008