Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > BOOK: Excel VBA 24-Hour Trainer
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 5th, 2014, 05:39 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
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

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
Reply With Quote
  #2 (permalink)  
Old January 6th, 2016, 12:35 AM
Wrox Author
Points: 191, Level: 3
Points: 191, Level: 3 Points: 191, Level: 3 Points: 191, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jan 2015
Location: San Francisco, California, USA
Posts: 35
Thanks: 0
Thanked 6 Times in 6 Posts

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.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 07:30 PM.

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