The April 2009 edition of the Renaissance Computer Systems Ltd. newsletter is now available at http://www.renaissance.co.il/newsletters/NewsApr09.pdf
In this Newsletter:
Renaissance sponsors Internet and Mobile Boot Camp
Speaking of Startups…
Tools, Technologies, and Techniques – Visual Studio Database Edition (“Data Dude”)
On the Lighter Side - Everything's amazing, nobody's happy
UPDATE #2: Thanks to the comment by Tony, making 2 simple changes to the code eliminates the need for step (3) below.
I’ve commented out the line
Set oOutlookApp = GetObject(, "Outlook.Application")
and changed
Set olNS = oOutlookApp.GetNamespace("MAPI")
to
' By following change eliminates the security access prompts!
'Set olNS = oOutlookApp.GetNamespace("MAPI")
Set olNS = ThisOutlookSession.GetNamespace("MAPI")
UPDATE: A critical line of code seems to have fallen off when I copied the code to the original post – I have added the line
Item.Save
to the code below.
For some reason, Microsoft has never supported mail merging of documents to email with an attachment. Until now, I always managed to work around this limitation. However, when we recently completed our Renaissance Case Studies document, I wanted to send out the PDF to our email distribution list.
Alas, a quick search for mail-merging with attachments returns a bunch of commercial tools, but there was only one good example of VBA code to do this in word – found here. Unfortunately, for some reason I was not able to get that code to work and didn’t have/want to spend the time to debug it (it could very well have been some silly/simple issue on my part). Instead I used it as a starting point for my own VBA function, which I will share below.
Before I get to the code, let me outline the steps to create the final emails:
(1) Create a normal email mail-merge document – without any attachment – and generate the emails to be sent.
(2) Execute the VBA function / Macro Set Attachment and enter the full path to the desired attachment when prompted by the dialog.
(3) You will normally be prompted with a security warning dialog for each outgoing message that you try to access. If you are sending more than just a few emails at a time here, I suggest you that you download and run the free utility Express ClickYes to automatically click yes for you every time.
Here is the VBA code I used for the SetAttachment function/Macro. It is provided “As is” – it worked well for me, but you’ll have to confirm and/or modify it for your scenarios.
Sub SetAttachment()
Dim i As Long
Dim OutlookApp As Outlook.Application
Dim Item As Outlook.MailItem
Dim Filepath As String, message As String, title As String
' This sub assumes that this macro is being run from within Outlook
On Error Resume Next
‘Set OutlookApp = GetObject(, "Outlook.Application")
message = "Enter the full path to the attachment." ' Set prompt.
title = " Email Attachment Path" ' Set title.
' Display message, title
Filepath = InputBox(message, title)
' iterate through all items in the Outlook Outbox
Dim olNS As Outlook.NameSpace
Dim MyFolder As Outlook.MAPIFolder
Dim count As Integer
' By following change eliminates the security access prompts!
'Set olNS = oOutlookApp.GetNamespace("MAPI")
Set olNS = ThisOutlookSession.GetNamespace("MAPI")
Set MyFolder = olNS.GetDefaultFolder(olFolderOutbox)
For i = 1 To MyFolder.Items.count
Set Item = MyFolder.Items(i)
Item.Attachments.Add Trim(Filepath), olByValue, 1
Item.Save
Item.Send
count = count + 1
Next i
Set Item = Nothing
MsgBox count & " files have been attached."
'Clean up
Set OutlookApp = Nothing
End Sub
I recently listened to a podcast with Guy Kawasaki, where he talked about successful companies and innovation. His position is that successful innovation is not necessarily revolutionary breakthroughs – but rather, the execution of new/improved ideas.
In thinking about this, I realized that Guy’s concept applies to Microsoft as well as to my company, Renaissance Computer Systems.
In the case of Microsoft, we always hear claims that Microsoft “stole” this technology or that idea and is not really an innovator. A different way of looking at it, however, is that Microsoft’s contribution and innovation is in the execution of those ideas/technologies. You can’t really deny Microsoft’s ability to take an idea, improve upon it (to a greater or lesser degree), and expertly execute a plan to get that technology into the hands of developers and make it as easy as possible for them to develop great applications with those technologies.
Similarly for my company, providing custom software development services per se is hardly innovative these days. However, the execution of our plan to provide those services – how we provide them to our clients, what is our specific value proposition, and what are the tangible results for our clients – THAT is our innovation.
If you are tired of being abused by your friends and neighbors for not Twittering enough (or at all), you can send you tormentors the link to the video below.
This video humorously presents a different view of the Twitter phenomenon. Enjoy!
via Lior