By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,644 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,644 IT Pros & Developers. It's quick & easy.

moving emails in outlook - type mismatch error

P: 88
hi all,

i have used the following macro to move unimportant (i.e. non-work related) mail in my outlook inbox into a folder in personal folders. it has worked for a long time, but suddenly it gives a "type mismatch" error when trying to move the mailitem.

Expand|Select|Wrap|Line Numbers
  1. Sub UnimportantMail()
  2.     Dim myTargetFolder As MAPIFolder
  3.     Dim myCurrentItem As Outlook.MailItem
  4.  
  5.     Set myCurrentItem = Application.ActiveExplorer.Selection
  6.     Set myTargetFolder = Outlook.GetNamespace("MAPI").Folders("Personal Folders").Folders("Unimportant stuff")
  7.  
  8.     myCurrentItem.UnRead = False
  9.  
  10.     myCurrentItem.Move (myTargetFolder)
  11.  
  12.     Set myCurrentItem = Nothing
  13.     Set myTargetFolder = Nothing
  14. End Sub
i have the same problem in all other macros trying to move anything (both folders and mailitems) around in outlook. why has this error suddenly started to occur while the macro worked just fine with the exact same code before, and what can i do about it?

thank you in advance for your help!
Nov 26 '07 #1
Share this Question
Share on Google+
7 Replies


P: 88
[tilt tilt...]

i really need help with this - i use these macros all the time, and when nothing's working everything takes twice as much time as it does if they work... so please - help! ;)
Nov 26 '07 #2

Expert 5K+
P: 8,434
At a guess, you've just upgraded Outlook or something.

Which line throws the error?
Nov 28 '07 #3

P: 88
At a guess, you've just upgraded Outlook or something.

Which line throws the error?
line 10:
Expand|Select|Wrap|Line Numbers
  1. myCurrentItem.Move (myTargetFolder)
Dec 6 '07 #4

P: 88
and by the way (excuse the double posting, i didn't find the edit button) i don't think outlook has updated recently. maybe it has, but in that case it was just a very minor update, since i didn't notice. corporate networks...
Dec 7 '07 #5

Expert 5K+
P: 8,434
Sorry for the delay, I've been away. It's a shame nobody else has jumped into the thread, as I don't know anything about Outlook.

The only thing I can suggest is to try removing the brackets around myTargetFolder, just to see whether it makes any difference.
Dec 9 '07 #6

P: 88
Sorry for the delay, I've been away. It's a shame nobody else has jumped into the thread, as I don't know anything about Outlook.

The only thing I can suggest is to try removing the brackets around myTargetFolder, just to see whether it makes any difference.
you must have magic fingers - it works! thanks!

i really do feel happy i started .net - passing parameters to a routine without parenthesis feels just odd... and a compiler getting a "type mismatch" error when you try this way is even worse. do you know if there's any way to write macros in vb.net instead?

anyway, thanks for helping me out!
Dec 11 '07 #7

Expert 5K+
P: 8,434
you must have magic fingers - it works! thanks!
Glad to hear it. :) I've always had a bit of a knack for debugging.

i really do feel happy i started .net - passing parameters to a routine without parenthesis feels just odd... and a compiler getting a "type mismatch" error when you try this way is even worse. do you know if there's any way to write macros in vb.net instead?
No idea, sorry.

The parameter syntax all seems pretty straightforward to me, because I've used VB and its predecessors for so long. Putting parentheses around the parameter forces it to be treated as an expression and resolved first, before passing it. In this case, my guess is the result might have been a string from the object's default property or something.

anyway, thanks for helping me out!
That's what we're here for. :)
Dec 12 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.