Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

E-mailing from Excel Q

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sean - 23 Jan 2008 15:38 GMT
I use Ron de Bruin's Outlook object model (body) code for sending
Excel related matter via e-mail. All works great but is there a way to
direct the mail from a particular mail A/c that I have on my Outlook
(2003)?

I have 2 e-mail A/c's set up using address for Company A and address
for Company B, how could I change the code so that the mail is sent
from "address for Company A" or vice versa?

Thanks
Ron de Bruin - 23 Jan 2008 15:46 GMT
hi Sean

See the tips page
http://www.rondebruin.nl/mail/tips2.htm

If you want to change the sender name and reply address add this code line

'The receiver can see the original mail address in the properties if he want
.SentOnBehalfOfName = """SenderName"" <Reply@Address.com>"




Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

>I use Ron de Bruin's Outlook object model (body) code for sending
> Excel related matter via e-mail. All works great but is there a way to
[quoted text clipped - 6 lines]
>
> Thanks
Sean - 23 Jan 2008 15:56 GMT
Thanks Ron, is there no way other than having "Sent on Behalf of",
even though there is a valid outlook a/c that it could be routed
through (apart from the default a/c)?
Ron de Bruin - 23 Jan 2008 16:06 GMT
Yes It is possible to change accounts with VBA
I see if I can dig up a code example for you so you can test it.

I have only one account in Outlook (I am a OE/windows Mail fan)

I see if I have time this evening

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

> Thanks Ron, is there no way other than having "Sent on Behalf of",
> even though there is a valid outlook a/c that it could be routed
> through (apart from the default a/c)?
Sean - 23 Jan 2008 16:24 GMT
Thanks Ron, the .sendonbehalfofname works great except I just wish to
see the other A/c as the "From name & address" rather than the
default.

I tried various suggestions you have made on past post such as
           .SenderName = """ABC Company"""
           .SenderEmailAddress = "<reports@abccompany.com>"

But they just send from the name on the default a/c

If the above were to work on a valid outlook a/c, is it the "Log in"
information which controls where it is sent from and hence must be
included within the VB?
JP - 23 Jan 2008 16:55 GMT
There was a thread about changing the sending account in one of the
Outlook newsgroups (I believe microsoft.public.outlook.program_vba),
I'll try to find it and send you a link, but I believe the response
was that it isn't possible without CDO/Redemption.

--JP

> Thanks Ron, the .sendonbehalfofname works great except I just wish to
> see the other A/c as the "From name & address" rather than the
[quoted text clipped - 9 lines]
> information which controls where it is sent from and hence must be
> included within the VB?
JP - 23 Jan 2008 16:57 GMT
Found it --

http://tinyurl.com/yv7wgs

HTH,
JP

> Thanks Ron, the .sendonbehalfofname works great except I just wish to
> see the other A/c as the "From name & address" rather than the
[quoted text clipped - 9 lines]
> information which controls where it is sent from and hence must be
> included within the VB?
Sean - 23 Jan 2008 17:11 GMT
Thanks for the link

I have heard of redemption but not quite sure how to apply it. I'm
assuming I would have to change my (Ron de Bruin's) entire code, which
I'd prefer not to do as its quite involved
JP - 23 Jan 2008 17:26 GMT
Redemption only requires a few changes to your code, check out the
link in the other thread, there is some
sample code for how to set the sending account.

http://www.dimastr.com/redemption/rdo/rdomail.htm#properties

HTH,
JP

> Thanks for the link
>
> I have heard of redemption but not quite sure how to apply it. I'm
> assuming I would have to change my (Ron de Bruin's) entire code, which
> I'd prefer not to do as its quite involved
Sean - 23 Jan 2008 18:59 GMT
Thanks JP, off site at the moment so ca't test, but is it the case I
could leave code as is and add the following, it may well work?

set Session = CreateObject("Redemption.RDOSession")
Session.Logon
set Drafts = Session.GetDefaultFolder(olFolderDrafts)
set Msg = Drafts.Items.Add
set Account = Session.Accounts("My ISP account")
Msg.Account = Account

<my code here>

Msg.Save
Msg.Send

I have other code in my original hat sets, the "To"; "Subject";
"Message Body" etc so don't wish to touch them
JP - 23 Jan 2008 19:54 GMT
I'm not that familiar with Redemption, you may want to post your code
in that newsgroup (microsoft.public.outlook.program_vba) and mention
that you want to use Redemption to set the sending account when
automating Outlook from Excel. Also you definitely should post more of
your code.

HTH,
JP

> Thanks JP, off site at the moment so ca't test, but is it the case I
> could leave code as is and add the following, it may well work?
[quoted text clipped - 13 lines]
> I have other code in my original hat sets, the "To"; "Subject";
> "Message Body" etc so don't wish to touch them
Ron de Bruin - 24 Jan 2008 16:26 GMT
Hi Sean

The Outlook guys tell me this

Use Redemption or read this thread
http://www.vbaexpress.com/forum/showthread.php?t=8076&p=64353

In 2007 you can use the new mailItem.SendUsingAccount property

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

> Thanks Ron, the .sendonbehalfofname works great except I just wish to
> see the other A/c as the "From name & address" rather than the
[quoted text clipped - 9 lines]
> information which controls where it is sent from and hence must be
> included within the VB?
Sean - 26 Jan 2008 14:49 GMT
I've installed Redemption but I'm lost as to how I tweak my code. My
original working code is below. It appears
that I need to place the following code somewhere in my code, but I
get a "property is read only" on the first line just below

   Set Session = CreateObject("Redemption.RDOSession")
   Session.Logon
   Set Drafts = Session.GetDefaultFolder(olFolderDrafts)
   Set Msg = Drafts.Items.Add
   Set Account = Session.Accounts("123 Reporting")
   Msg.Account = Account
   Msg.Send

On the site  http://www.dimastr.com/redemption/ FAQ # 14 it seems to
detail exactly what I want, but I don't know how to integrate it in my
code, the code they suggest is below

set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = MailItem
tag = sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From")
tag = tag or &H1E     'the type is PT_STRING8
sItem.Fields(Tag) = "Someone <whoever@domain.com>"
sItem.Subject = sItem.Subject  'to trick Outlook into thinking that
something has changed
sItem.Save

Sub Mail_From_Excel()
   Dim FileExtStr As String
   Dim FileFormatNum As Long
   Dim Sourcewb As Workbook
   Dim Destwb As Workbook
   Dim TempFilePath As String
   Dim TempFileName As String
   Dim OutApp As Object
   Dim OutMail As Object
   Dim sh As Worksheet

   With Application
       .ScreenUpdating = False
       .EnableEvents = False
   End With

   Set Sourcewb = ActiveWorkbook

   Sourcewb.Sheets(Array("Mail", "E-YTD")).Copy
   Set Destwb = ActiveWorkbook

   'Determine the Excel version and file extension/format
   With Destwb
       If Val(Application.Version) < 12 Then
           'You use Excel 97-2003
           FileExtStr = ".xls": FileFormatNum = -4143
       Else
           'You use Excel 2007
           'We exit the sub when your answer is NO in the security
dialog that you only
           'see  when you copy a sheet from a xlsm file with macro's
disabled.
           If Sourcewb.Name = .Name Then
               With Application
                   .ScreenUpdating = True
                   .EnableEvents = True
               End With
               MsgBox "Your answer is NO in the security dialog"
               Exit Sub
           Else
               Select Case Sourcewb.FileFormat
               Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
               Case 52:
                   If .HasVBProject Then
                       FileExtStr = ".xlsm": FileFormatNum = 52
                   Else
                       FileExtStr = ".xlsx": FileFormatNum = 51
                   End If
               Case 56: FileExtStr = ".xls": FileFormatNum = 56
               Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
               End Select
           End If
       End If
   End With

   TempFilePath = Environ$("temp") & "\"
   TempFileName = "Part of " & Sourcewb.Name & " " & Format(Now,
"dd-
mmm-yy h-mm")

   ActiveWindow.TabRatio = 0.908

   Set OutApp = CreateObject("Outlook.Application")
   OutApp.Session.Logon
   Set OutMail = OutApp.CreateItem(0)

   For Each cell In ThisWorkbook.Sheets("Mail") _
   .Columns("BA").Cells.SpecialCells(xlCellTypeConstants)
       If cell.Value Like "?*@?*.?*" Then
           strto = strto & cell.Value & ";"
       End If
   Next
   strto = Left(strto, Len(strto) - 1)

   With Destwb
       .SaveAs TempFilePath & TempFileName & FileExtStr,
FileFormat:=FileFormatNum

       On Error Resume Next
       With OutMail
           .To = ""
           .CC = ""
           .BCC = strto
           .Subject = ThisWorkbook.Sheets("Mail").Range("A1").Value
           .Body = ""
           .Attachments.Add Destwb.FullName
           .ReadReceiptRequested = True
           .Importance = 1
           .DeferredDeliveryTime =
ThisWorkbook.Sheets("Mail").Range("B1").Value
           .Send
       End With
       On Error GoTo 0
       .Close savechanges:=False
   End With

   Kill TempFilePath & TempFileName & FileExtStr

   Set OutMail = Nothing
   Set OutApp = Nothing

   With Application
       .ScreenUpdating = True
       .EnableEvents = True
   End With
End Sub
Ron de Bruin - 29 Jan 2008 15:54 GMT
I never used Redemption Sean so I can't help you.
I have no time on this moment to test it for you, sorry

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

> I've installed Redemption but I'm lost as to how I tweak my code. My
> original working code is below. It appears
[quoted text clipped - 129 lines]
>    End With
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.