![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
I have tried to research this and I can not find much.
Here is the code I have. It still sends from the defualt account. I have 21 email accounts and this is to be sending from the 21st account. I in the below code, I have tried using from the 3r account. Sub Mail_Selection_Range_Outlook_Body() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object With Application .EnableEvents = False .ScreenUpdating = False End With Set rng = Nothing On Error Resume Next 'Only the visible cells in the selection 'Set rng = Selection.SpecialCells(xlCellTypeVisible) 'You can also use a range if you want Set rng = Sheets("Invoice").Range("B7:I47").SpecialCells(xlC ellTypeVisible) emailname = Range("M21").Value bbcname = " MsgBox emailname On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected" & _ vbNewLine & "please correct and try again.", vbOKOnly Exit Sub End If Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display .SendUsingAccount = OutApp.Accounts(3) End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub |
Ads |
#2
|
|||
|
|||
![]()
You need to set SendUsingAccount before you send the item.
-- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... I have tried to research this and I can not find much. Here is the code I have. It still sends from the defualt account. I have 21 email accounts and this is to be sending from the 21st account. I in the below code, I have tried using from the 3r account. Sub Mail_Selection_Range_Outlook_Body() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object With Application .EnableEvents = False .ScreenUpdating = False End With Set rng = Nothing On Error Resume Next 'Only the visible cells in the selection 'Set rng = Selection.SpecialCells(xlCellTypeVisible) 'You can also use a range if you want Set rng = Sheets("Invoice").Range("B7:I47").SpecialCells(xlC ellTypeVisible) emailname = Range("M21").Value bbcname = " MsgBox emailname On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected" & _ vbNewLine & "please correct and try again.", vbOKOnly Exit Sub End If Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display .SendUsingAccount = OutApp.Accounts(3) End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub |
#3
|
|||
|
|||
![]()
Hello Sue,
I have tried moving it up in the code block, but I still can not change the account. What am I missing? I know you have told others that it needs to be an object, but how do I do that? Is it going to be an object the way I have my code written? I KNOW I am close, but.... Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... You need to set SendUsingAccount before you send the item. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... I have tried to research this and I can not find much. Here is the code I have. It still sends from the defualt account. I have 21 email accounts and this is to be sending from the 21st account. I in the below code, I have tried using from the 3r account. Sub Mail_Selection_Range_Outlook_Body() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object With Application .EnableEvents = False .ScreenUpdating = False End With Set rng = Nothing On Error Resume Next 'Only the visible cells in the selection 'Set rng = Selection.SpecialCells(xlCellTypeVisible) 'You can also use a range if you want Set rng = Sheets("Invoice").Range("B7:I47").SpecialCells(xlC ellTypeVisible) emailname = Range("M21").Value bbcname = " MsgBox emailname On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected" & _ vbNewLine & "please correct and try again.", vbOKOnly Exit Sub End If Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display .SendUsingAccount = OutApp.Accounts(3) End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub |
#4
|
|||
|
|||
![]()
OutApp.Accounts(3) returns an Account object.
I would comment out the On Error Resume Next statement to make sure an error isn't being overlooked. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... Hello Sue, I have tried moving it up in the code block, but I still can not change the account. What am I missing? I know you have told others that it needs to be an object, but how do I do that? Is it going to be an object the way I have my code written? I KNOW I am close, but.... Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... You need to set SendUsingAccount before you send the item. "Bruce" wrote in message ... I have tried to research this and I can not find much. Here is the code I have. It still sends from the defualt account. I have 21 email accounts and this is to be sending from the 21st account. I in the below code, I have tried using from the 3r account. Sub Mail_Selection_Range_Outlook_Body() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object With Application .EnableEvents = False .ScreenUpdating = False End With Set rng = Nothing On Error Resume Next 'Only the visible cells in the selection 'Set rng = Selection.SpecialCells(xlCellTypeVisible) 'You can also use a range if you want Set rng = Sheets("Invoice").Range("B7:I47").SpecialCells(xlC ellTypeVisible) emailname = Range("M21").Value bbcname = " MsgBox emailname On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected" & _ vbNewLine & "please correct and try again.", vbOKOnly Exit Sub End If Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display .SendUsingAccount = OutApp.Accounts(3) End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub |
#5
|
|||
|
|||
![]()
'K
I commented out the on error, and now I am getting an error. run-time error '438': Object doesn't support this program or method. I DO have Outlook 12 selected in toolreferences .SendUsingAccount = OutApp.Accounts(3) is the line that throws the error. Here is how the code block is right now: Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) ' On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .SendUsingAccount = OutApp.Accounts(3) .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display End With What am I missing? I HAVE gotten the following code working, and msgbox oAccount shows me the account name for each loop. Dim oAccount As Outlook.Account ' For Each oAccount In Application.Session.Accounts ' If oAccount.AccountType = olPop3 Then ' Dim oMail As Outlook.MailItem ' Set oMail = Application.CreateItem(olMailItem) ' oMail.Subject = "Sent using POP3 Account" ' oMail.Recipients.Add emailname ' oMail.Recipients.ResolveAll ' oMail.SendUsingAccount = oAccount ' oMail.Send ' MsgBox oAccount ' ' End If ' Next Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... OutApp.Accounts(3) returns an Account object. I would comment out the On Error Resume Next statement to make sure an error isn't being overlooked. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... Hello Sue, I have tried moving it up in the code block, but I still can not change the account. What am I missing? I know you have told others that it needs to be an object, but how do I do that? Is it going to be an object the way I have my code written? I KNOW I am close, but.... Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... You need to set SendUsingAccount before you send the item. "Bruce" wrote in message ... I have tried to research this and I can not find much. Here is the code I have. It still sends from the defualt account. I have 21 email accounts and this is to be sending from the 21st account. I in the below code, I have tried using from the 3r account. Sub Mail_Selection_Range_Outlook_Body() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object With Application .EnableEvents = False .ScreenUpdating = False End With Set rng = Nothing On Error Resume Next 'Only the visible cells in the selection 'Set rng = Selection.SpecialCells(xlCellTypeVisible) 'You can also use a range if you want Set rng = Sheets("Invoice").Range("B7:I47").SpecialCells(xlC ellTypeVisible) emailname = Range("M21").Value bbcname = " MsgBox emailname On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected" & _ vbNewLine & "please correct and try again.", vbOKOnly Exit Sub End If Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display .SendUsingAccount = OutApp.Accounts(3) End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub |
#6
|
|||
|
|||
![]()
The object browser is our friend. It's Namespace.Acccounts, not Application.Accounts. Good way to remember: Anything that is dependent on mail profile settings derives from the Namespace object.
-- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... 'K I commented out the on error, and now I am getting an error. run-time error '438': Object doesn't support this program or method. I DO have Outlook 12 selected in toolreferences .SendUsingAccount = OutApp.Accounts(3) is the line that throws the error. Here is how the code block is right now: Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) ' On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .SendUsingAccount = OutApp.Accounts(3) .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display End With What am I missing? I HAVE gotten the following code working, and msgbox oAccount shows me the account name for each loop. Dim oAccount As Outlook.Account ' For Each oAccount In Application.Session.Accounts ' If oAccount.AccountType = olPop3 Then ' Dim oMail As Outlook.MailItem ' Set oMail = Application.CreateItem(olMailItem) ' oMail.Subject = "Sent using POP3 Account" ' oMail.Recipients.Add emailname ' oMail.Recipients.ResolveAll ' oMail.SendUsingAccount = oAccount ' oMail.Send ' MsgBox oAccount ' ' End If ' Next Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... OutApp.Accounts(3) returns an Account object. I would comment out the On Error Resume Next statement to make sure an error isn't being overlooked. "Bruce" wrote in message ... Hello Sue, I have tried moving it up in the code block, but I still can not change the account. What am I missing? I know you have told others that it needs to be an object, but how do I do that? Is it going to be an object the way I have my code written? I KNOW I am close, but.... Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... You need to set SendUsingAccount before you send the item. "Bruce" wrote in message ... I have tried to research this and I can not find much. Here is the code I have. It still sends from the defualt account. I have 21 email accounts and this is to be sending from the 21st account. I in the below code, I have tried using from the 3r account. Sub Mail_Selection_Range_Outlook_Body() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object With Application .EnableEvents = False .ScreenUpdating = False End With Set rng = Nothing On Error Resume Next 'Only the visible cells in the selection 'Set rng = Selection.SpecialCells(xlCellTypeVisible) 'You can also use a range if you want Set rng = Sheets("Invoice").Range("B7:I47").SpecialCells(xlC ellTypeVisible) emailname = Range("M21").Value bbcname = " MsgBox emailname On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected" & _ vbNewLine & "please correct and try again.", vbOKOnly Exit Sub End If Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display .SendUsingAccount = OutApp.Accounts(3) End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub |
#7
|
|||
|
|||
![]()
Sue,
Thank you for your help. I made the change to ..SendUsingAccount = namespace.Accounts(3) but now I am getting RT error 424 Object required Againg this is being thrown on the line: ..SendUsingAccount = Namespace.Accounts(3) Also, just to be clear (I did not put it in my first post) this is in EXCEL! Thanks again Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... The object browser is our friend. It's Namespace.Acccounts, not Application.Accounts. Good way to remember: Anything that is dependent on mail profile settings derives from the Namespace object. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... 'K I commented out the on error, and now I am getting an error. run-time error '438': Object doesn't support this program or method. I DO have Outlook 12 selected in toolreferences .SendUsingAccount = OutApp.Accounts(3) is the line that throws the error. Here is how the code block is right now: Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) ' On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .SendUsingAccount = OutApp.Accounts(3) .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display End With What am I missing? I HAVE gotten the following code working, and msgbox oAccount shows me the account name for each loop. Dim oAccount As Outlook.Account ' For Each oAccount In Application.Session.Accounts ' If oAccount.AccountType = olPop3 Then ' Dim oMail As Outlook.MailItem ' Set oMail = Application.CreateItem(olMailItem) ' oMail.Subject = "Sent using POP3 Account" ' oMail.Recipients.Add emailname ' oMail.Recipients.ResolveAll ' oMail.SendUsingAccount = oAccount ' oMail.Send ' MsgBox oAccount ' ' End If ' Next Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... OutApp.Accounts(3) returns an Account object. I would comment out the On Error Resume Next statement to make sure an error isn't being overlooked. "Bruce" wrote in message ... Hello Sue, I have tried moving it up in the code block, but I still can not change the account. What am I missing? I know you have told others that it needs to be an object, but how do I do that? Is it going to be an object the way I have my code written? I KNOW I am close, but.... Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... You need to set SendUsingAccount before you send the item. "Bruce" wrote in message ... I have tried to research this and I can not find much. Here is the code I have. It still sends from the defualt account. I have 21 email accounts and this is to be sending from the 21st account. I in the below code, I have tried using from the 3r account. Sub Mail_Selection_Range_Outlook_Body() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object With Application .EnableEvents = False .ScreenUpdating = False End With Set rng = Nothing On Error Resume Next 'Only the visible cells in the selection 'Set rng = Selection.SpecialCells(xlCellTypeVisible) 'You can also use a range if you want Set rng = Sheets("Invoice").Range("B7:I47").SpecialCells(xlC ellTypeVisible) emailname = Range("M21").Value bbcname = " MsgBox emailname On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected" & _ vbNewLine & "please correct and try again.", vbOKOnly Exit Sub End If Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display .SendUsingAccount = OutApp.Accounts(3) End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub |
#8
|
|||
|
|||
![]()
Namespace is the name of the object, in other words the class, that you need to use, not the name of an object variable in your application. You need to instantiate a Namespace object using the Outlook object model's Application.GetNamespace method.
-- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... Sue, Thank you for your help. I made the change to .SendUsingAccount = namespace.Accounts(3) but now I am getting RT error 424 Object required Againg this is being thrown on the line: .SendUsingAccount = Namespace.Accounts(3) Also, just to be clear (I did not put it in my first post) this is in EXCEL! Thanks again Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... The object browser is our friend. It's Namespace.Acccounts, not Application.Accounts. Good way to remember: Anything that is dependent on mail profile settings derives from the Namespace object. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... 'K I commented out the on error, and now I am getting an error. run-time error '438': Object doesn't support this program or method. I DO have Outlook 12 selected in toolreferences .SendUsingAccount = OutApp.Accounts(3) is the line that throws the error. Here is how the code block is right now: Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) ' On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .SendUsingAccount = OutApp.Accounts(3) .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display End With What am I missing? I HAVE gotten the following code working, and msgbox oAccount shows me the account name for each loop. Dim oAccount As Outlook.Account ' For Each oAccount In Application.Session.Accounts ' If oAccount.AccountType = olPop3 Then ' Dim oMail As Outlook.MailItem ' Set oMail = Application.CreateItem(olMailItem) ' oMail.Subject = "Sent using POP3 Account" ' oMail.Recipients.Add emailname ' oMail.Recipients.ResolveAll ' oMail.SendUsingAccount = oAccount ' oMail.Send ' MsgBox oAccount ' ' End If ' Next Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... OutApp.Accounts(3) returns an Account object. I would comment out the On Error Resume Next statement to make sure an error isn't being overlooked. "Bruce" wrote in message ... Hello Sue, I have tried moving it up in the code block, but I still can not change the account. What am I missing? I know you have told others that it needs to be an object, but how do I do that? Is it going to be an object the way I have my code written? I KNOW I am close, but.... Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... You need to set SendUsingAccount before you send the item. "Bruce" wrote in message ... I have tried to research this and I can not find much. Here is the code I have. It still sends from the defualt account. I have 21 email accounts and this is to be sending from the 21st account. I in the below code, I have tried using from the 3r account. Sub Mail_Selection_Range_Outlook_Body() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object With Application .EnableEvents = False .ScreenUpdating = False End With Set rng = Nothing On Error Resume Next 'Only the visible cells in the selection 'Set rng = Selection.SpecialCells(xlCellTypeVisible) 'You can also use a range if you want Set rng = Sheets("Invoice").Range("B7:I47").SpecialCells(xlC ellTypeVisible) emailname = Range("M21").Value bbcname = " MsgBox emailname On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected" & _ vbNewLine & "please correct and try again.", vbOKOnly Exit Sub End If Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display .SendUsingAccount = OutApp.Accounts(3) End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub |
#9
|
|||
|
|||
![]()
Sue,
I hate being a pain... I am not as strong of a programmer as you give me credit for:.) Could you please give me a little code sample that would allow me to send a message to an reciepiant, and use a different account than the defualt? Here is pretty much what I can see that should shoot the email out. Sub Mail_Selection_Range_Outlook_Body1() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object emailname = " bbcname = " MsgBox "Invoice is being sent to : " & emailname Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) Namespace = Outlook.Application.GetNamespace("MAPI") With OutMail .To = emailname .CC = "" .BCC = bbcname .SendUsingAccount = Namespace.Accounts(3) 'how do I select a different account? .Subject = "Invoice for - " .HTMLBody = "this is a test" .Send 'or use .Display End With Set OutMail = Nothing Set OutApp = Nothing End Sub Thank you very much for your continued help! Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... Namespace is the name of the object, in other words the class, that you need to use, not the name of an object variable in your application. You need to instantiate a Namespace object using the Outlook object model's Application.GetNamespace method. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... Sue, Thank you for your help. I made the change to .SendUsingAccount = namespace.Accounts(3) but now I am getting RT error 424 Object required Againg this is being thrown on the line: .SendUsingAccount = Namespace.Accounts(3) Also, just to be clear (I did not put it in my first post) this is in EXCEL! Thanks again Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... The object browser is our friend. It's Namespace.Acccounts, not Application.Accounts. Good way to remember: Anything that is dependent on mail profile settings derives from the Namespace object. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... 'K I commented out the on error, and now I am getting an error. run-time error '438': Object doesn't support this program or method. I DO have Outlook 12 selected in toolreferences .SendUsingAccount = OutApp.Accounts(3) is the line that throws the error. Here is how the code block is right now: Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) ' On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .SendUsingAccount = OutApp.Accounts(3) .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display End With What am I missing? I HAVE gotten the following code working, and msgbox oAccount shows me the account name for each loop. Dim oAccount As Outlook.Account ' For Each oAccount In Application.Session.Accounts ' If oAccount.AccountType = olPop3 Then ' Dim oMail As Outlook.MailItem ' Set oMail = Application.CreateItem(olMailItem) ' oMail.Subject = "Sent using POP3 Account" ' oMail.Recipients.Add emailname ' oMail.Recipients.ResolveAll ' oMail.SendUsingAccount = oAccount ' oMail.Send ' MsgBox oAccount ' ' End If ' Next Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... OutApp.Accounts(3) returns an Account object. I would comment out the On Error Resume Next statement to make sure an error isn't being overlooked. "Bruce" wrote in message ... Hello Sue, I have tried moving it up in the code block, but I still can not change the account. What am I missing? I know you have told others that it needs to be an object, but how do I do that? Is it going to be an object the way I have my code written? I KNOW I am close, but.... Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... You need to set SendUsingAccount before you send the item. "Bruce" wrote in message ... I have tried to research this and I can not find much. Here is the code I have. It still sends from the defualt account. I have 21 email accounts and this is to be sending from the 21st account. I in the below code, I have tried using from the 3r account. Sub Mail_Selection_Range_Outlook_Body() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object With Application .EnableEvents = False .ScreenUpdating = False End With Set rng = Nothing On Error Resume Next 'Only the visible cells in the selection 'Set rng = Selection.SpecialCells(xlCellTypeVisible) 'You can also use a range if you want Set rng = Sheets("Invoice").Range("B7:I47").SpecialCells(xlC ellTypeVisible) emailname = Range("M21").Value bbcname = " MsgBox emailname On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected" & _ vbNewLine & "please correct and try again.", vbOKOnly Exit Sub End If Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display .SendUsingAccount = OutApp.Accounts(3) End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub |
#10
|
|||
|
|||
![]()
It looks like you're still not grapsing the issues of instantiating an object variable and using object methods. Hate to say it but this is VBA 101, and if you can't get past this, you're not going to get anywhere. Let's try again:
Accounts are an object property of the Namespace object. The Namespace is an object property of the Outlook.Application object from which all Outlook objects need to be derived. Therefore, to get an Account, you need an Outlook.Application object to start with. That you already have: Set OutApp = CreateObject("Outlook.Application") Next you need a Namespace object. If you're automating Outlook from another application, you need to use the GetNamespace method. That looks like this: Set OutNS = OutApp.GetNamespace("MAPI") OutNS.Logon If Outlook is already running, that will be enough. Otherwise, your Logon statement may need to specify a mail profile or give the user a chance to choose one. Read the Help topic on Namespace.Logon for details. To get an Account object to use in setting the sending account, use its name to retrive it from the Accounts collection of the Namespace object that we just instantiated: Set OutAcct = OutNS.Accounts("name_of_the_account") Make sense? Can you take it from there? -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... Sue, I hate being a pain... I am not as strong of a programmer as you give me credit for:.) Could you please give me a little code sample that would allow me to send a message to an reciepiant, and use a different account than the defualt? Here is pretty much what I can see that should shoot the email out. Sub Mail_Selection_Range_Outlook_Body1() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object emailname = " bbcname = " MsgBox "Invoice is being sent to : " & emailname Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) Namespace = Outlook.Application.GetNamespace("MAPI") With OutMail .To = emailname .CC = "" .BCC = bbcname .SendUsingAccount = Namespace.Accounts(3) 'how do I select a different account? .Subject = "Invoice for - " .HTMLBody = "this is a test" .Send 'or use .Display End With Set OutMail = Nothing Set OutApp = Nothing End Sub Thank you very much for your continued help! Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... Namespace is the name of the object, in other words the class, that you need to use, not the name of an object variable in your application. You need to instantiate a Namespace object using the Outlook object model's Application.GetNamespace method. "Bruce" wrote in message ... Sue, Thank you for your help. I made the change to .SendUsingAccount = namespace.Accounts(3) but now I am getting RT error 424 Object required Againg this is being thrown on the line: .SendUsingAccount = Namespace.Accounts(3) Also, just to be clear (I did not put it in my first post) this is in EXCEL! Thanks again Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... The object browser is our friend. It's Namespace.Acccounts, not Application.Accounts. Good way to remember: Anything that is dependent on mail profile settings derives from the Namespace object. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Bruce" wrote in message ... 'K I commented out the on error, and now I am getting an error. run-time error '438': Object doesn't support this program or method. I DO have Outlook 12 selected in toolreferences .SendUsingAccount = OutApp.Accounts(3) is the line that throws the error. Here is how the code block is right now: Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) ' On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .SendUsingAccount = OutApp.Accounts(3) .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display End With What am I missing? I HAVE gotten the following code working, and msgbox oAccount shows me the account name for each loop. Dim oAccount As Outlook.Account ' For Each oAccount In Application.Session.Accounts ' If oAccount.AccountType = olPop3 Then ' Dim oMail As Outlook.MailItem ' Set oMail = Application.CreateItem(olMailItem) ' oMail.Subject = "Sent using POP3 Account" ' oMail.Recipients.Add emailname ' oMail.Recipients.ResolveAll ' oMail.SendUsingAccount = oAccount ' oMail.Send ' MsgBox oAccount ' ' End If ' Next Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... OutApp.Accounts(3) returns an Account object. I would comment out the On Error Resume Next statement to make sure an error isn't being overlooked. "Bruce" wrote in message ... Hello Sue, I have tried moving it up in the code block, but I still can not change the account. What am I missing? I know you have told others that it needs to be an object, but how do I do that? Is it going to be an object the way I have my code written? I KNOW I am close, but.... Thanks Bruce "Sue Mosher [MVP-Outlook]" wrote in message ... You need to set SendUsingAccount before you send the item. "Bruce" wrote in message ... I have tried to research this and I can not find much. Here is the code I have. It still sends from the defualt account. I have 21 email accounts and this is to be sending from the 21st account. I in the below code, I have tried using from the 3r account. Sub Mail_Selection_Range_Outlook_Body() ' Don't forget to copy the function RangetoHTML in the module. ' Working in Office 2000-2007 Dim rng As Range Dim OutApp As Object Dim OutMail As Object With Application .EnableEvents = False .ScreenUpdating = False End With Set rng = Nothing On Error Resume Next 'Only the visible cells in the selection 'Set rng = Selection.SpecialCells(xlCellTypeVisible) 'You can also use a range if you want Set rng = Sheets("Invoice").Range("B7:I47").SpecialCells(xlC ellTypeVisible) emailname = Range("M21").Value bbcname = " MsgBox emailname On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected" & _ vbNewLine & "please correct and try again.", vbOKOnly Exit Sub End If Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = emailname .CC = "" .BCC = bbcname .Subject = "Invoice for - " & Range("L6").Value & " - " & Application.Text(Range("L4").Value, "mmm-dd-yyyy") .HTMLBody = RangetoHTML(rng) .Send 'or use .Display .SendUsingAccount = OutApp.Accounts(3) End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Installed trial Office 2007 but Outlook 2007 is missing | phoenix | Outlook - Installation | 16 | August 25th 08 09:04 PM |
InfoPath 2007 Forms sent to Outlook 2007 not rendering correctly | Rob Stark | Outlook - Using Forms | 5 | February 22nd 07 11:58 PM |
can't uninstall 2007 Trial to install Office 2007 | Christopher Glaeser | Outlook - Installation | 0 | February 16th 07 05:29 AM |
Outlook 2007 will not open SharePoint 2007 task assignment messages | ACK | Outlook - General Queries | 3 | February 16th 07 03:15 AM |
SharePoint (WSS) 2007 / Outlook 2007 - Alert - Cannot open this item | Harry Pfleger | Outlook - General Queries | 2 | January 3rd 07 12:15 AM |