Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > BOOK: Excel VBA 24-Hour Trainer
|
BOOK: Excel VBA 24-Hour Trainer
This is the forum to discuss the Wrox book Excel VBA 24-Hour Trainer by Tom Urtis; ISBN: 978-0-470-89069-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Excel VBA 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 5th, 2014, 05:39 AM
Registered User
 
Join Date: Oct 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 28 E-Mailing A Single Worksheet

I follow Tom's book exercise to send worksheet to 4 recipients but it end up with run time error 2147467259 - operation failed.
Can i know what is this problem?

The code as below:

Sub EmailAttachmentRecipients()

Dim objOutlook As Object
Dim objNameSpace As Object
Dim objInbox As Object
Dim objMailItem
Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNameSpace("MAPI")
Set objInbox = objNameSpace.Folders(1)
Set objMailItem = objOutlook.CreateItem(0)

Dim strTo As String
Dim i As Integer
strTo = " "
i = 1

Do
strTo = strTo & Cells(i, 1).Value & ";"
i = i + 1
Loop Until IsEmpty(Cells(i, 1))
strTo = Mid(strTo, 1, Len(strTo) - 2)

With objMailItem
.To = strTo
.Subject = "Test of multiple recipients"
.Body = "Hello everyone, this is a test of multiple recipients with a workbook attachment."
.Attachments.Add ActiveWorkbook.FullName
.Display 'Change to Send
End With

Set objOutlook = Nothing
Set objNameSpace = Nothing
Set objInbox = Nothing
Set objMailItem = Nothing

End Sub
 
Old January 6th, 2016, 12:35 AM
Wrox Author
 
Join Date: Jan 2015
Posts: 35
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Hi, and thanks for buying the book.

That error can be due to a couple of reasons. For example, if the strTo variable contains an illogical recipient name (such as, in a cell, a name has a space or disallowed character), VBA would raise an error. It might also be due to a server issue or a default IT setting that does not allow, or expect that, Outlook will be required to send the email. Hard to say without knowing the background of the environment you're working with.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 28 Sample Code randaljay BOOK: Professional C# 4.0 and .NET 4 3 July 31st, 2013 05:38 AM
Chapter 28 - MEF Architecture mhanson BOOK: Professional C# 4.0 and .NET 4 1 April 7th, 2011 04:04 PM
Chapter 28 code missing rCobbley BOOK: Excel 2003 VBA Programmer's Reference 0 November 1st, 2006 05:42 PM
Beginning C# Source code(Chapter 27,28) jiguang_ma Wrox Book Feedback 0 December 15th, 2005 08:25 AM
Chapter 28 - downloading assemblies Tangyu BOOK: Professional C#, 2nd and 3rd Editions 0 May 23rd, 2005 10:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.