Outlook move to public folder

  • Thread starter Thread starter wodahsehtmai
  • Start date Start date
W

wodahsehtmai

I keep getting a "one or more parameter values are not valid" on the
"objEmail.Move objFolder" line.

I can move it to an inbox sub folder without error, and I can manually
drag the item to the public folder without error. Any ideas on what's
wrong here? (I have publishing author client permisions on the
folder.)

John

Sub MoveSpam()
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 = objInbox.Folders("Test")

'Set objFolder = objNS.Folders("Public Folders").Folders("All Public
Folders").Folders("GFI AntiSpam Folders").Folders("This is spam
email")
For intX = 1 To objNS.Folders.Count
If objNS.Folders.Item(intX).Name = "Public Folders" Then
Set objFolder = objNS.Folders.Item(intX).Folders("All Public
Folders")
Set objFolder = objFolder.Folders("GFI AntiSpam Folders")
Set objFolder = objFolder.Folders("This is spam email")
Exit For
End If
Next

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

Set oSelection = Application.ActiveExplorer.Selection

'intCount = oSelection.Count
'For i = intCount To 1 Step -1
' Set objItem = oSelection.Item(i)
' If objFolder.DefaultItemType = olMailItem Then
' If objItem.Class = olMail Then
' objItem.Move objFolder
' End If
' End If
' 'objItem.Copy objFolder
'Next

For intX = ActiveExplorer.Selection.Count To 1 Step -1
Set objX = ActiveExplorer.Selection.Item(intX)
If objX.Class = olMail Then
Set objEmail = objX
objEmail.Move objFolder
End If
Next

'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
 
If no one here has any ideas for me, does anyone have a suggestion on
where to go to get help on this one?
 
I finally got some time to test your code here, after I created the correct
public folder tree. After declaring various undeclared variables the code
worked with no problems moving items to the public folder.

If it works for you manually dragging and dropping items into the public
folder then permissions shouldn't be a problem, but is there any way to
elevate your permissions to owner just to make sure it's not some odd
permissions issue?

Are any of the items you're attempting to move flagged as complete? That's
known to prevent moving until you clear the flag and then set it back again
after the move.

Although the code worked here see if it works for you when you call Move as
a function:
Set objMoved = objEmail.Move(objFolder)

Any problems running any other macros?

What version of Outlook and Windows?
 
After declaring various undeclared variables the code

I wasn't getting any error messages on that but I think I have
everything declared now (VB is not my primary langauge and the code was
mostly picked up from other posts here.) I'll put the updated code at
the end of this message.

Done and I gave myself full admin and directory rights as well. No
change.

objItem.FlagStatus = olNoFlag

Same error

Not that I'm aware of.

Client:
Windows XP SP2
Outlook 2002 SP3

Server:
SBS2000 SP4
Exchange Server 2000 SP3

I am not an overly experienced exchange administrator, so it is
possible that there is something wrong in that setup. It is mostly a
default SBS setup.

BTW the code works fine if I use:

'Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
'Set objFolder = objInbox.Folders("Spam")

Instead of the public folder.

Thanks for your help on this.

John

Revised Code:

Sub MoveSpam()
Dim objFolder As Outlook.MAPIFolder
Dim objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace
Dim objItem As Outlook.MailItem
Dim objMoved As Outlook.MailItem

Set objNS = Application.GetNamespace("MAPI")

'Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
'Set objFolder = objInbox.Folders("Spam")
Set objFolder = objNS.Folders("Public Folders").Folders("All Public
Folders").Folders("GFI AntiSpam Folders").Folders("This is spam email")

If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation,
"INVALID FOLDER"
Exit Sub
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 intX = ActiveExplorer.Selection.Count To 1 Step -1
Set objItem = ActiveExplorer.Selection.Item(intX)
If objItem.Class = olMail Then
'objItem.Move objFolder
Set objMoved = objItem.Move(objFolder)
End If
Next

Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
Set objMoved = Nothing
End Sub
 
If it works for Inbox it should work for the public folder. The code worked
for me for a public folder, so my only guess is it's some permissions issue.
The only move issue I'm aware of is the one with a flag marked complete, but
that would also affect moves to any other folder.

Still the same error message?
 
I posted a reply yesterday but it's not showing.

Yes

Maybe I have something setup wrong on the server, but it's odd that I
can drag and drop the file into the same directory without any
problems.

John
 
It's odd but the code works here so there's nothing intrinsically wrong with
it. I have no idea why it's not working for you.
 
Thanks for checking this out for me. I greatly appreciate it.

So I'm guessing if I want to resolve this the next step would be paid
tech support. Or is there another place I should try first?

John
 
Paid support is certainly an option. I'd also maybe explore setting up
different computers and/or virtual machines and see if things are the same
there. I'd also be playing with new profiles and possibly impersonating
other users to see how deep this problem goes. All I can say is running as
usual as admin and accessing the PF as owner the code worked for me. I also
ran it as my dog, who's an Exchange admin but a power user as a Windows
logon and who had publishing author rights on that PF.
 
You were right, I played around a bit more and found it.

PGP was interfering with it. Shutting down PGP alowed it to move just
fine. Now I have to see if I can work around the PGP problem.

John
 
Interesting. Thanks for following up and letting us know it was PGP causing
the problem.
 
Back
Top