On 09/06/2011 16:20:03, Boyd wrote:
Quote:
I have the following VBA code (behind an Access button) that moves all
emails from one Outlook folder to another. The code works fine for
users of Office 2007, but not with Office 2010. I'm receiving an
"Operation Failed" error on "fld.Items(1).Move fld2". Any thoughts?
Dim appOutlook As Outlook.Application
Dim nms As Outlook.nameSpace
Dim fld As Outlook.MAPIFolder
Dim fld2 As Outlook.MAPIFolder
Set appOutlook = GetObject(, "Outlook.Application")
Set nms = appOutlook.GetNamespace("MAPI")
Set fld = nms.PickFolder
While fld.Items.Count > 0
Set fld2 = fld.Folders("Emails Processed")
fld.Items(1).Move fld2
Wend |
Try, but remove all the bits about a progress meter. (I can't stand the
horrible little thing that Office 2010 use, so I created my own progress
meter)
Function ZZCopyContacts(FromFolder As String, ToFolder As String)
' ?CopyContacts("Test", "Temporary")
Dim OlApp As Outlook.Application
Dim OlNS As Outlook.NameSpace
Dim MyFolder As MAPIFolder
Dim OlFromFolder As MAPIFolder
Dim OlToFolder As MAPIFolder
Dim OlItems As Items
Dim CopiedItem As Object
Dim i As Integer
' Fields for Progress Meter
Dim PMFrmMax As Long
Dim RecordNo As Long
Dim Smoothness As Integer
On Error GoTo CopyContacts_Err
Set OlApp = CreateObject("Outlook.Application")
Set OlNS = OlApp.GetNamespace("MAPI")
Set MyFolder = OlNS.GetDefaultFolder(olFolderContacts)
If MyFolder.Name = ToFolder Then
Set OlToFolder = OlNS.GetDefaultFolder(olFolderContacts)
Else
Set OlToFolder = MyFolder.Folders(ToFolder)
End If
If MyFolder.Name = FromFolder Then
Set OlFromFolder = OlNS.GetDefaultFolder(olFolderContacts)
Else
Set OlFromFolder = MyFolder.Folders(FromFolder)
End If
' Set maxima etc
PMFrmMax = CLng(OlFromFolder.Items.Count)
Smoothness = Int(PMFrmMax \ 200)
If Nz(Smoothness) < 1 Then
Smoothness = 1
End If
' Set default caption, label & colour
' If titles are blank, default ones are loaded
' if colours are negative, default red and green are loaded
PMeterRainbow.RainShowProgress
PMeterRainbow.RainSetCaption tion = "Outlook" ' Progress Meter Caption
PMeterRainbow.RainSetTitle itle = "Copying contacts from " & FromFolder & "
to " & ToFolder PMeterRainbow.RainSetLabToProcess = "" ' Progress Meter label
Caption PMeterRainbow.RainSetLabProcessed = "" ' Progress Meter label
Caption' Progress Meter PMeterRainbow.RainSetFromColour = -1 ' Default from
colour PMeterRainbow.RainSetToColour = -1 ' Default to colour
PMeterRainbow.RainSetToProcess = PMFrmMax ' RecordCount
PMeterRainbow.RainSetSmoothness = Smoothness
For i = 1 To OlFromFolder.Items.Count
Set OlItems = OlFromFolder.Items
Set CopiedItem = OlItems.Item(i).Copy
CopiedItem.Move OlToFolder
RecordNo = RecordNo + 1
If RecordNo Mod Smoothness = 0 Then
PMeterRainbow.RainIncOne (RecordNo)
End If
Next i
PMeterRainbow.RainHideProgress
Exit Function
CopyContacts_Err:
If ZZIsLoaded("ProgressMeterRainbow") Then
PMeterRainbow.RainHideProgress
End If
Stop
End Function