patricknyc
06-13-2016, 09:38 PM
Hello,
I'm a bit lost. Getting a compile error "Sub or Function not defined" when running the macro below in Outlook 2010. GetFolderPath is being highlighted in yellow.
This macro is supposed to move emails >60 days old to a different PST folder. I have checked that the path names are correct and also tried moving it to a different folder, with the same result. Would greatly appreciate any help! Thanks!!
------ Macro below with item giving a compile error in bold----
Sub MoveAgedMail()
Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim objVariant As Variant
Dim lngMovedItems As Long
Dim intCount As Integer
Dim intDateDiff As Integer
Set objOutlook = Application
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)
'Use a folder in a different data file
Set objDestFolder = GetFolderPath("Patricks\Archives inbox")
For intCount = objSourceFolder.Items.Count To 1 Step -1
Set objVariant = objSourceFolder.Items.Item(intCount)
DoEvents
If objVariant.Class = olMail Then
intDateDiff = DateDiff("d", objVariant.SentOn, Now)
' adjust number of days as needed.
If intDateDiff > 60 Then
objVariant.Move objDestFolder
'count the # of items moved
lngMovedItems = lngMovedItems + 1
End If
End If
Next
' Display the number of items that were moved.
MsgBox "Moved " & lngMovedItems & " messages(s)."
Set objDestFolder = Nothing
End Sub
I'm a bit lost. Getting a compile error "Sub or Function not defined" when running the macro below in Outlook 2010. GetFolderPath is being highlighted in yellow.
This macro is supposed to move emails >60 days old to a different PST folder. I have checked that the path names are correct and also tried moving it to a different folder, with the same result. Would greatly appreciate any help! Thanks!!
------ Macro below with item giving a compile error in bold----
Sub MoveAgedMail()
Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim objVariant As Variant
Dim lngMovedItems As Long
Dim intCount As Integer
Dim intDateDiff As Integer
Set objOutlook = Application
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)
'Use a folder in a different data file
Set objDestFolder = GetFolderPath("Patricks\Archives inbox")
For intCount = objSourceFolder.Items.Count To 1 Step -1
Set objVariant = objSourceFolder.Items.Item(intCount)
DoEvents
If objVariant.Class = olMail Then
intDateDiff = DateDiff("d", objVariant.SentOn, Now)
' adjust number of days as needed.
If intDateDiff > 60 Then
objVariant.Move objDestFolder
'count the # of items moved
lngMovedItems = lngMovedItems + 1
End If
End If
Next
' Display the number of items that were moved.
MsgBox "Moved " & lngMovedItems & " messages(s)."
Set objDestFolder = Nothing
End Sub