![]() |
SenderName Value
Is there a way to get the SenderName Value via code?
From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. Any help is greatly appreciated. Mark Ivey |
SenderName Value
Outlook version? Code environment for your project?
-- 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/jumpstart.aspx "Mark Ivey" wrote in message ... Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. Any help is greatly appreciated. Mark Ivey |
SenderName Value
On Wed, 16 May 2007 17:41:52 -0500, "Mark Ivey"
wrote: Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. Any help is greatly appreciated. Mark Ivey There is a very easy way to do this. Just save the email message to a file. There will be a line in the file "Sender: Fred J. Muggs " plus the sender's email. Use the split command on the line with a colon as the separator. Take a look at the file and there will be a number of fields in there. With a little program to loop through the fields in the text file, you may be able to get everything you need very easily. By using the spilit command and the resulting array, you will get the field name and the field value in the array. Then, you can process each field as you like. Depending on your needs, it can be a good solution. Greg |
SenderName Value
Outlook version?
I am designing it at home in Outlook 2002, but plan on using it at work for Outlook 2003. Code environment for your project? VBA (and VBS if needed). "Sue Mosher [MVP-Outlook]" wrote in message ... Outlook version? Code environment for your project? -- 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/jumpstart.aspx "Mark Ivey" wrote in message ... Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. Any help is greatly appreciated. Mark Ivey |
SenderName Value
Greg,
I appreciate your feedback, but I wasn't planning on saving the email to a file outside of Outlook. My plan is to be able to select one or more emails and click on a button (to fire a macro) and have these emails sent to their appropriate backup folder in my Personal folder list. For example: If I select and email from John Brown, and then click on this button. I would expect this email to be moved to my personal folder "2007" and into a subfolder labeled "John Brown". If someone has already invented the wheel with respect to what I am needing, I would greatly appreciate some code snippets (VBA preferably). TIA... Mark Ivey "Greg" wrote in message ... On Wed, 16 May 2007 17:41:52 -0500, "Mark Ivey" wrote: Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. Any help is greatly appreciated. Mark Ivey There is a very easy way to do this. Just save the email message to a file. There will be a line in the file "Sender: Fred J. Muggs " plus the sender's email. Use the split command on the line with a colon as the separator. Take a look at the file and there will be a number of fields in there. With a little program to loop through the fields in the text file, you may be able to get everything you need very easily. By using the spilit command and the resulting array, you will get the field name and the field value in the array. Then, you can process each field as you like. Depending on your needs, it can be a good solution. Greg |
SenderName Value
Outlook 2002 VBA will give you security prompts, but Outlook 2003 won't, as long as you derive all objects from the intrinsic Application object.
Greg's suggestion doesn't help, BTW, because the SaveAs method triggers a security prompt. -- 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/jumpstart.aspx "Mark Ivey" wrote in message ... I am designing it at home in Outlook 2002, but plan on using it at work for Outlook 2003. VBA (and VBS if needed). Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. |
SenderName Value
Thanks for the info Sue...
Here is some code I found and altered a bit on the web from Eric Legault - B.A, MCP, MCSD, Outlook MVP. My problem is not knowing how to reference the subfolder I need due to these security items I have mentioned. Do you think the code below should work for Outlook 2003? If not, could you make a suggestion. My biggest concern is this line: "Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName)" How do I reference a subfolder in my personal folders list with the variable "SenderName"? '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Outlook 2002 VBA will give you security prompts, but Outlook 2003 won't, as long as you derive all objects from the intrinsic Application object. Greg's suggestion doesn't help, BTW, because the SaveAs method triggers a security prompt. -- 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/jumpstart.aspx "Mark Ivey" wrote in message ... I am designing it at home in Outlook 2002, but plan on using it at work for Outlook 2003. VBA (and VBS if needed). Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. |
SenderName Value
Session.Folders returns the collection of top-level folders, i.e. all the individual .pst files or mailboxes. To get a non-default folder, you need to walk the folder hierarchy starting with that collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm
-- 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/jumpstart.aspx "Mark Ivey" wrote in message ... Thanks for the info Sue... Here is some code I found and altered a bit on the web from Eric Legault - B.A, MCP, MCSD, Outlook MVP. My problem is not knowing how to reference the subfolder I need due to these security items I have mentioned. Do you think the code below should work for Outlook 2003? If not, could you make a suggestion. My biggest concern is this line: "Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName)" How do I reference a subfolder in my personal folders list with the variable "SenderName"? '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Outlook 2002 VBA will give you security prompts, but Outlook 2003 won't, as long as you derive all objects from the intrinsic Application object. Greg's suggestion doesn't help, BTW, because the SaveAs method triggers a security prompt. "Mark Ivey" wrote in message ... I am designing it at home in Outlook 2002, but plan on using it at work for Outlook 2003. VBA (and VBS if needed). Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. |
SenderName Value
On Wed, 16 May 2007 21:35:08 -0400, "Sue Mosher [MVP-Outlook]"
wrote: Outlook 2002 VBA will give you security prompts, but Outlook 2003 won't, as long as you derive all objects from the intrinsic Application object. Greg's suggestion doesn't help, BTW, because the SaveAs method triggers a security prompt. I should have mentioned that. You have to deal with the security prompt. Just do a search to find Sue's articles on that. Thanks. |
SenderName Value
Sue,
Can you tell me what is wrong with my code below? I cannot seem to figure out the right way to reference the SenderName value. It keeps throwing the following error for line 9. Run-time error '91': Object variable or With block variable not set '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007").Folders(objItem.Se nderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Session.Folders returns the collection of top-level folders, i.e. all the individual .pst files or mailboxes. To get a non-default folder, you need to walk the folder hierarchy starting with that collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm -- 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/jumpstart.aspx "Mark Ivey" wrote in message ... Thanks for the info Sue... Here is some code I found and altered a bit on the web from Eric Legault - B.A, MCP, MCSD, Outlook MVP. My problem is not knowing how to reference the subfolder I need due to these security items I have mentioned. Do you think the code below should work for Outlook 2003? If not, could you make a suggestion. My biggest concern is this line: "Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName)" How do I reference a subfolder in my personal folders list with the variable "SenderName"? '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Outlook 2002 VBA will give you security prompts, but Outlook 2003 won't, as long as you derive all objects from the intrinsic Application object. Greg's suggestion doesn't help, BTW, because the SaveAs method triggers a security prompt. "Mark Ivey" wrote in message ... I am designing it at home in Outlook 2002, but plan on using it at work for Outlook 2003. VBA (and VBS if needed). Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. |
SenderName Value
You mean this statement? (Please, please tell us which statement is causing problems rather than giving a line number.)
Set objFolder = Outlook.Session.Folders("2007").Folders(objItem.Se nderName) First, there's no object named Outlook in your code. Second, you already have a Namespace object through which you can access the Folders collection. You instantiated it with this statement: Set objNS = Application.GetNamespace("MAPI") Therefore, the correct statement, assuming you have a .pst file with the display name 2007, would be: Set objFolder = objNS.Folders("2007").Folders(objItem.SenderName) -- 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/jumpstart.aspx "Mark Ivey" wrote in message ... Sue, Can you tell me what is wrong with my code below? I cannot seem to figure out the right way to reference the SenderName value. It keeps throwing the following error for line 9. Run-time error '91': Object variable or With block variable not set '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007").Folders(objItem.Se nderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Session.Folders returns the collection of top-level folders, i.e. all the individual .pst files or mailboxes. To get a non-default folder, you need to walk the folder hierarchy starting with that collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm "Mark Ivey" wrote in message ... Thanks for the info Sue... Here is some code I found and altered a bit on the web from Eric Legault - B.A, MCP, MCSD, Outlook MVP. My problem is not knowing how to reference the subfolder I need due to these security items I have mentioned. Do you think the code below should work for Outlook 2003? If not, could you make a suggestion. My biggest concern is this line: "Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName)" How do I reference a subfolder in my personal folders list with the variable "SenderName"? '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Outlook 2002 VBA will give you security prompts, but Outlook 2003 won't, as long as you derive all objects from the intrinsic Application object. Greg's suggestion doesn't help, BTW, because the SaveAs method triggers a security prompt. "Mark Ivey" wrote in message ... I am designing it at home in Outlook 2002, but plan on using it at work for Outlook 2003. VBA (and VBS if needed). Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. |
SenderName Value
Thanks Sue...
"Sue Mosher [MVP-Outlook]" wrote in message ... You mean this statement? (Please, please tell us which statement is causing problems rather than giving a line number.) Set objFolder = Outlook.Session.Folders("2007").Folders(objItem.Se nderName) First, there's no object named Outlook in your code. Second, you already have a Namespace object through which you can access the Folders collection. You instantiated it with this statement: Set objNS = Application.GetNamespace("MAPI") Therefore, the correct statement, assuming you have a .pst file with the display name 2007, would be: Set objFolder = objNS.Folders("2007").Folders(objItem.SenderName) -- 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/jumpstart.aspx "Mark Ivey" wrote in message ... Sue, Can you tell me what is wrong with my code below? I cannot seem to figure out the right way to reference the SenderName value. It keeps throwing the following error for line 9. Run-time error '91': Object variable or With block variable not set '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007").Folders(objItem.Se nderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Session.Folders returns the collection of top-level folders, i.e. all the individual .pst files or mailboxes. To get a non-default folder, you need to walk the folder hierarchy starting with that collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm "Mark Ivey" wrote in message ... Thanks for the info Sue... Here is some code I found and altered a bit on the web from Eric Legault - B.A, MCP, MCSD, Outlook MVP. My problem is not knowing how to reference the subfolder I need due to these security items I have mentioned. Do you think the code below should work for Outlook 2003? If not, could you make a suggestion. My biggest concern is this line: "Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName)" How do I reference a subfolder in my personal folders list with the variable "SenderName"? '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Outlook 2002 VBA will give you security prompts, but Outlook 2003 won't, as long as you derive all objects from the intrinsic Application object. Greg's suggestion doesn't help, BTW, because the SaveAs method triggers a security prompt. "Mark Ivey" wrote in message ... I am designing it at home in Outlook 2002, but plan on using it at work for Outlook 2003. VBA (and VBS if needed). Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. |
SenderName Value
Sue,
It appears that the item that is throwing the error is "objItem.SenderName" in the same line you referenced. It is saying "Object variable or With block variable not set". Am I not referencing this value correctly? What is the appropriate method to call this value? TIA, Mark Ivey "Sue Mosher [MVP-Outlook]" wrote in message ... You mean this statement? (Please, please tell us which statement is causing problems rather than giving a line number.) Set objFolder = Outlook.Session.Folders("2007").Folders(objItem.Se nderName) First, there's no object named Outlook in your code. Second, you already have a Namespace object through which you can access the Folders collection. You instantiated it with this statement: Set objNS = Application.GetNamespace("MAPI") Therefore, the correct statement, assuming you have a .pst file with the display name 2007, would be: Set objFolder = objNS.Folders("2007").Folders(objItem.SenderName) -- 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/jumpstart.aspx "Mark Ivey" wrote in message ... Sue, Can you tell me what is wrong with my code below? I cannot seem to figure out the right way to reference the SenderName value. It keeps throwing the following error for line 9. Run-time error '91': Object variable or With block variable not set '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007").Folders(objItem.Se nderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Session.Folders returns the collection of top-level folders, i.e. all the individual .pst files or mailboxes. To get a non-default folder, you need to walk the folder hierarchy starting with that collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm "Mark Ivey" wrote in message ... Thanks for the info Sue... Here is some code I found and altered a bit on the web from Eric Legault - B.A, MCP, MCSD, Outlook MVP. My problem is not knowing how to reference the subfolder I need due to these security items I have mentioned. Do you think the code below should work for Outlook 2003? If not, could you make a suggestion. My biggest concern is this line: "Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName)" How do I reference a subfolder in my personal folders list with the variable "SenderName"? '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Outlook 2002 VBA will give you security prompts, but Outlook 2003 won't, as long as you derive all objects from the intrinsic Application object. Greg's suggestion doesn't help, BTW, because the SaveAs method triggers a security prompt. "Mark Ivey" wrote in message ... I am designing it at home in Outlook 2002, but plan on using it at work for Outlook 2003. VBA (and VBS if needed). Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. |
SenderName Value
Your code doesn't set objItem to a value until it gets to the For Each loop. Therefore, any statements referring to that object need to be inside the loop.
-- 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/jumpstart.aspx "Mark Ivey" wrote in message ... Sue, It appears that the item that is throwing the error is "objItem.SenderName" in the same line you referenced. It is saying "Object variable or With block variable not set". Am I not referencing this value correctly? What is the appropriate method to call this value? TIA, Mark Ivey "Sue Mosher [MVP-Outlook]" wrote in message ... You mean this statement? (Please, please tell us which statement is causing problems rather than giving a line number.) Set objFolder = Outlook.Session.Folders("2007").Folders(objItem.Se nderName) First, there's no object named Outlook in your code. Second, you already have a Namespace object through which you can access the Folders collection. You instantiated it with this statement: Set objNS = Application.GetNamespace("MAPI") Therefore, the correct statement, assuming you have a .pst file with the display name 2007, would be: Set objFolder = objNS.Folders("2007").Folders(objItem.SenderName) "Mark Ivey" wrote in message ... Sue, Can you tell me what is wrong with my code below? I cannot seem to figure out the right way to reference the SenderName value. It keeps throwing the following error for line 9. Run-time error '91': Object variable or With block variable not set '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007").Folders(objItem.Se nderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Session.Folders returns the collection of top-level folders, i.e. all the individual .pst files or mailboxes. To get a non-default folder, you need to walk the folder hierarchy starting with that collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm "Mark Ivey" wrote in message ... Thanks for the info Sue... Here is some code I found and altered a bit on the web from Eric Legault - B.A, MCP, MCSD, Outlook MVP. My problem is not knowing how to reference the subfolder I need due to these security items I have mentioned. Do you think the code below should work for Outlook 2003? If not, could you make a suggestion. My biggest concern is this line: "Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName)" How do I reference a subfolder in my personal folders list with the variable "SenderName"? '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Outlook 2002 VBA will give you security prompts, but Outlook 2003 won't, as long as you derive all objects from the intrinsic Application object. Greg's suggestion doesn't help, BTW, because the SaveAs method triggers a security prompt. "Mark Ivey" wrote in message ... I am designing it at home in Outlook 2002, but plan on using it at work for Outlook 2003. VBA (and VBS if needed). Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. |
Archiving email to a personal folder
Thanks for your help Sue...
Sorry to be thick-headed, but I am still learning Outlook VBA. I find VBA to be much easier in Excel. Here is my finished product if anyone was interested: __________________________________________________ ________________________________ Special thanks to: Eric Legault, Steven Harvey, and Sue Mosher for helping derive the version posted below. __________________________________________________ ________________________________ Sub ArchiveToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Dim myFolder As String myFolder = Format(Date, "yyyy") ' My personal folder is labeled as the current year (ie - '2007') Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = objNS.Folders(myFolder) If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If FolderExist(objItem.SenderName) = False Then objFolder.Folders.Add (objItem.SenderName) End If Set objFolder = objNS.Folders(myFolder).Folders(objItem.SenderName ) If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder Set objFolder = objNS.Folders(myFolder) End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub Function FolderExist(sFileName As String) As Boolean FolderExist = IIf(Dir(sFileName, vbDirectory) "", True, False) End Function __________________________________________________ ________________________________ Mark Ivey "Sue Mosher [MVP-Outlook]" wrote in message ... Your code doesn't set objItem to a value until it gets to the For Each loop. Therefore, any statements referring to that object need to be inside the loop. -- 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/jumpstart.aspx "Mark Ivey" wrote in message ... Sue, It appears that the item that is throwing the error is "objItem.SenderName" in the same line you referenced. It is saying "Object variable or With block variable not set". Am I not referencing this value correctly? What is the appropriate method to call this value? TIA, Mark Ivey "Sue Mosher [MVP-Outlook]" wrote in message ... You mean this statement? (Please, please tell us which statement is causing problems rather than giving a line number.) Set objFolder = Outlook.Session.Folders("2007").Folders(objItem.Se nderName) First, there's no object named Outlook in your code. Second, you already have a Namespace object through which you can access the Folders collection. You instantiated it with this statement: Set objNS = Application.GetNamespace("MAPI") Therefore, the correct statement, assuming you have a .pst file with the display name 2007, would be: Set objFolder = objNS.Folders("2007").Folders(objItem.SenderName) "Mark Ivey" wrote in message ... Sue, Can you tell me what is wrong with my code below? I cannot seem to figure out the right way to reference the SenderName value. It keeps throwing the following error for line 9. Run-time error '91': Object variable or With block variable not set '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007").Folders(objItem.Se nderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Session.Folders returns the collection of top-level folders, i.e. all the individual .pst files or mailboxes. To get a non-default folder, you need to walk the folder hierarchy starting with that collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm "Mark Ivey" wrote in message ... Thanks for the info Sue... Here is some code I found and altered a bit on the web from Eric Legault - B.A, MCP, MCSD, Outlook MVP. My problem is not knowing how to reference the subfolder I need due to these security items I have mentioned. Do you think the code below should work for Outlook 2003? If not, could you make a suggestion. My biggest concern is this line: "Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName)" How do I reference a subfolder in my personal folders list with the variable "SenderName"? '_________________________________________________ _________________________________ Sub MoveSelectedMessagesToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Outlook.Session.Folders("2007" & objItem.SenderName) If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub '_________________________________________________ _________________________________ "Sue Mosher [MVP-Outlook]" wrote in message ... Outlook 2002 VBA will give you security prompts, but Outlook 2003 won't, as long as you derive all objects from the intrinsic Application object. Greg's suggestion doesn't help, BTW, because the SaveAs method triggers a security prompt. "Mark Ivey" wrote in message ... I am designing it at home in Outlook 2002, but plan on using it at work for Outlook 2003. VBA (and VBS if needed). Is there a way to get the SenderName Value via code? From what I can tell, this is trapped behind some of the security features in Outlook. I am wanting to reference this value so I can utilize it in an effort to make an archiving macro. |
All times are GMT +1. The time now is 07:45 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com