<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: VB: Putting filenames in a message body.</title>
	<link>http://ask.metafilter.com/104186/VB-Putting-filenames-in-a-message-body/</link>
	<description>Comments on Ask MetaFilter post VB: Putting filenames in a message body.</description>
	<pubDate>Tue, 14 Oct 2008 03:45:27 -0800</pubDate>
	<lastBuildDate>Tue, 14 Oct 2008 03:45:27 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: VB: Putting filenames in a message body.</title>
		<link>http://ask.metafilter.com/104186/VB-Putting-filenames-in-a-message-body</link>	
		<description>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? &lt;br /&gt;&lt;br /&gt; I&apos;m not a programmer - I&apos;m just using a script that I ran across somewhere on the Internet. I&apos;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 &quot;inspirational message.&quot; Bonus: Can I point my current olItem.Body at a text file?&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;br&gt;
Sub ChangeSubject()&lt;br&gt;
Set oActiveExplorer = Application.ActiveExplorer&lt;br&gt;
MsgBox TypeName(oActiveExplorer.Selection)&lt;br&gt;
Set oSelection = oActiveExplorer.Selection&lt;br&gt;
    For I = 1 To oSelection.Count&lt;br&gt;
        Set olItem = oSelection.Item(I)&lt;br&gt;
        olItem.Subject = &quot;Your weekly inspirational message&quot;&lt;br&gt;
        olItem.Body = &quot;Inspirational Message&quot;&lt;br&gt;
        olItem.Send&lt;br&gt;
    Next&lt;br&gt;
End Sub&lt;br&gt;
&lt;/pre&gt;</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2008:site.104186</guid>
		<pubDate>Mon, 13 Oct 2008 23:25:05 -0800</pubDate>
		<dc:creator>bigmusic</dc:creator>
		
			<category>VB</category>
		
			<category>outlook</category>
		
			<category>programming</category>
		
			<category>message</category>
		
			<category>body</category>
		
			<category>attachment</category>
		
			<category>resolved</category>
		
	</item> <item>
		<title>By: NailsTheCat</title>
		<link>http://ask.metafilter.com/104186/VB-Putting-filenames-in-a-message-body#1507369</link>	
		<description>Not sure about VBScript, but in VBA to access the attachments&lt;br&gt;
&lt;br&gt;
Dim myAttachments As Attachments&lt;br&gt;
&lt;br&gt;
 Set myAttachments = myEmailObject.Attachments&lt;br&gt;
&lt;br&gt;
&apos;   Skip shortcuts and embedded messages&lt;br&gt;
    Do While myAttachments(AttachmentsCounter).Type = olOLE _&lt;br&gt;
            Or Left$(myAttachments(AttachmentsCounter).DisplayName, 8) = &quot;Shortcut&quot; _&lt;br&gt;
            Or InStr(myAttachments(AttachmentsCounter).FileName, &quot;.msg&quot;) &amp;gt; 0&lt;br&gt;
        AttachmentsCounter = AttachmentsCounter - 1&lt;br&gt;
        &lt;br&gt;
      DO SOMETHING WITH THE ATTACHMENT NAME perhaps&lt;br&gt;
&lt;br&gt;
            myEmailObject.Body = myEmailObject.Body &amp;amp; vbCrLf &amp;amp; myAttachments(AttachmentsCounter).DisplayName&lt;br&gt;
    Loop&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Now, if you want to load the entire body in from a file you could just read it in from the file thus:&lt;br&gt;
&lt;br&gt;
Dim f as long&lt;br&gt;
Dim myText as string&lt;br&gt;
&lt;br&gt;
f = FreeFile&lt;br&gt;
Open WHATEVERYOURPATHIS for input as f&lt;br&gt;
myText = Input$(LOF(f), #f)&lt;br&gt;
Close #f&lt;br&gt;
&lt;br&gt;
myEmail.body = mytext&lt;br&gt;
&lt;br&gt;
(Aircode so may not run first time but you get the idea..)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.104186-1507369</guid>
		<pubDate>Tue, 14 Oct 2008 03:45:27 -0800</pubDate>
		<dc:creator>NailsTheCat</dc:creator>
	</item><item>
		<title>By: bigmusic</title>
		<link>http://ask.metafilter.com/104186/VB-Putting-filenames-in-a-message-body#1508258</link>	
		<description>Shows what I know, this is a VBA script. I&apos;m getting a 424 error when I try to insert your code into the for loop above olItem.Send - I&apos;m not sure if I am doing this correctly.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.104186-1508258</guid>
		<pubDate>Tue, 14 Oct 2008 14:35:21 -0800</pubDate>
		<dc:creator>bigmusic</dc:creator>
	</item><item>
		<title>By: NailsTheCat</title>
		<link>http://ask.metafilter.com/104186/VB-Putting-filenames-in-a-message-body#1508310</link>	
		<description>I just tested the below code and it seemed to work for me. Note that I have declared all of the variables -- olItem is explicitly declared as MailItem which might be why you got that error.&lt;br&gt;
&lt;br&gt;
Sub ChangeSubject()&lt;br&gt;
&lt;br&gt;
Dim oActiveExplorer As Object&lt;br&gt;
Dim oSelection As Object&lt;br&gt;
Dim olItem As MailItem&lt;br&gt;
Dim myAttachments As Attachments&lt;br&gt;
Dim myAttach As Attachment&lt;br&gt;
Dim i As Integer&lt;br&gt;
Dim f As Long&lt;br&gt;
Dim myText As String&lt;br&gt;
Const MYPATH As String = &quot;c:\temp\temp.txt&quot;&lt;br&gt;
&lt;br&gt;
Set oActiveExplorer = Application.ActiveExplorer&lt;br&gt;
&lt;br&gt;
MsgBox TypeName(oActiveExplorer.Selection)&lt;br&gt;
&lt;br&gt;
Set oSelection = oActiveExplorer.Selection&lt;br&gt;
&lt;br&gt;
    For i = 1 To oSelection.Count&lt;br&gt;
&lt;br&gt;
        Set olItem = oSelection.Item(i)&lt;br&gt;
&lt;br&gt;
        olItem.Subject = &quot;Your weekly inspirational message&quot;&lt;br&gt;
        olItem.Body = &quot;Inspirational Message&quot;&lt;br&gt;
        &lt;br&gt;
        &apos; (1) get text from a file and replace the body with this&lt;br&gt;
        f = FreeFile&lt;br&gt;
        Open MYPATH For Input As f&lt;br&gt;
        myText = Input$(LOF(f), #f)&lt;br&gt;
        olItem.Body = myText&lt;br&gt;
        Close #f&lt;br&gt;
        &lt;br&gt;
        &apos; (2) add the filename of each attachments&lt;br&gt;
         Set myAttachments = olItem.Attachments&lt;br&gt;
        &apos; Skip shortcuts and embedded messages&lt;br&gt;
        For Each myAttach In myAttachments&lt;br&gt;
            With myAttach&lt;br&gt;
                If myAttach.Type &lt;&gt; olOLE _&lt;br&gt;
                    And Left$(myAttach.DisplayName, 8) &lt;&gt; &quot;Shortcut&quot; _&lt;br&gt;
                    And InStr(myAttach.FileName, &quot;.msg&quot;) = 0 Then&lt;br&gt;
                    olItem.Body = olItem.Body &amp;amp; vbCrLf &amp;amp; myAttach.DisplayName&lt;br&gt;
                End If&lt;br&gt;
            End With&lt;br&gt;
       &lt;br&gt;
        Next myAttach&lt;br&gt;
&lt;br&gt;
        olItem.Save&lt;br&gt;
        olItem.Send&lt;br&gt;
&lt;br&gt;
    Next i&lt;br&gt;
&lt;br&gt;
End Sub&lt;/&gt;&lt;/&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.104186-1508310</guid>
		<pubDate>Tue, 14 Oct 2008 15:30:44 -0800</pubDate>
		<dc:creator>NailsTheCat</dc:creator>
	</item><item>
		<title>By: bigmusic</title>
		<link>http://ask.metafilter.com/104186/VB-Putting-filenames-in-a-message-body#1508354</link>	
		<description>Works perfectly - thank you so much. I really need to learn how to program one of these days - I seem to want to customize so much of my software. It&apos;s just boggling to me that there is no general purpose language that I can use to script everything - greasemonkey for browswer customization, VBA for office stuff, AutoIT for GUI automation --- I&apos;m not sure I have the time or the inclination to learn them all. Python is attractive to me - but I can&apos;t use it in any of my applications that I use everyday.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.104186-1508354</guid>
		<pubDate>Tue, 14 Oct 2008 16:17:13 -0800</pubDate>
		<dc:creator>bigmusic</dc:creator>
	</item><item>
		<title>By: NailsTheCat</title>
		<link>http://ask.metafilter.com/104186/VB-Putting-filenames-in-a-message-body#1508390</link>	
		<description>Glad it worked! VBA is easy once you get the hang of it and there&apos;s a lot of resources online including the wonderful newsgroups (e.g. microsoft.public.outlook.*) -- I share your ambivalence about what to learn though.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.104186-1508390</guid>
		<pubDate>Tue, 14 Oct 2008 17:09:47 -0800</pubDate>
		<dc:creator>NailsTheCat</dc:creator>
	</item>
	</channel>
</rss>
