Shazam
04-11-2012, 02:32 PM
Hi,
I have a additional mailbox on my Outlook 2010 64-bit. I send mails on the behalf of another mail box. But when I send out a mail from the other mail box...it goes to my personal sent item folder. I would like the mail go to the SendAs behalf sent item folder.
So I found this code below but gives me an error when the code is activated.
"Run-time error '449':
Argument not optional"
I click on debug and it highlight this line.
Item.Move = olkFolder
Anyone can help me? or anyone has another version of this code?
Private WithEvents olkSentItems As Outlook.Items
Private Sub Application_Quit()
Set olkSentItems = Nothing
End Sub
Private Sub Application_Startup()
Set olkSentItems = Session.GetDefaultFolder(olFolderSentMail).Items
End Sub
Private Sub olkSentItems_ItemAdd(ByVal Item As Object)
Dim olkFolder As Outlook.MAPIFolder
If Item.Class = olMail Then
'Change the name on the following line as needed. It will have to match the name in the message exactly.
If Item.SenderName = "Support" Then
'Change the folder path on the following line to that of the folder you want the item moved to
Set olkFolder = OpenOutlookFolder("Mailbox - Support\Sent Items")
Item.Move = olkFolder
End If
End If
Set olkFolder = Nothing
End Sub
Function IsNothing(obj)
If TypeName(obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function
Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
Dim arrFolders As Variant, _
varFolder As Variant, _
olkFolder As Outlook.MAPIFolder
On Error GoTo ehOpenOutlookFolder
If strFolderPath = "" Then
Set OpenOutlookFolder = Nothing
Else
If Left(strFolderPath, 1) = "\" Then
strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
End If
arrFolders = Split(strFolderPath, "\")
For Each varFolder In arrFolders
If IsNothing(olkFolder) Then
Set olkFolder = Session.Folders(varFolder)
Else
Set olkFolder = olkFolder.Folders(varFolder)
End If
Next
Set OpenOutlookFolder = olkFolder
End If
On Error GoTo 0
Exit Function
ehOpenOutlookFolder:
Set OpenOutlookFolder = Nothing
On Error GoTo 0
End Function
I have a additional mailbox on my Outlook 2010 64-bit. I send mails on the behalf of another mail box. But when I send out a mail from the other mail box...it goes to my personal sent item folder. I would like the mail go to the SendAs behalf sent item folder.
So I found this code below but gives me an error when the code is activated.
"Run-time error '449':
Argument not optional"
I click on debug and it highlight this line.
Item.Move = olkFolder
Anyone can help me? or anyone has another version of this code?
Private WithEvents olkSentItems As Outlook.Items
Private Sub Application_Quit()
Set olkSentItems = Nothing
End Sub
Private Sub Application_Startup()
Set olkSentItems = Session.GetDefaultFolder(olFolderSentMail).Items
End Sub
Private Sub olkSentItems_ItemAdd(ByVal Item As Object)
Dim olkFolder As Outlook.MAPIFolder
If Item.Class = olMail Then
'Change the name on the following line as needed. It will have to match the name in the message exactly.
If Item.SenderName = "Support" Then
'Change the folder path on the following line to that of the folder you want the item moved to
Set olkFolder = OpenOutlookFolder("Mailbox - Support\Sent Items")
Item.Move = olkFolder
End If
End If
Set olkFolder = Nothing
End Sub
Function IsNothing(obj)
If TypeName(obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function
Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
Dim arrFolders As Variant, _
varFolder As Variant, _
olkFolder As Outlook.MAPIFolder
On Error GoTo ehOpenOutlookFolder
If strFolderPath = "" Then
Set OpenOutlookFolder = Nothing
Else
If Left(strFolderPath, 1) = "\" Then
strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
End If
arrFolders = Split(strFolderPath, "\")
For Each varFolder In arrFolders
If IsNothing(olkFolder) Then
Set olkFolder = Session.Folders(varFolder)
Else
Set olkFolder = olkFolder.Folders(varFolder)
End If
Next
Set OpenOutlookFolder = olkFolder
End If
On Error GoTo 0
Exit Function
ehOpenOutlookFolder:
Set OpenOutlookFolder = Nothing
On Error GoTo 0
End Function