Help - VB Macro no longer work

  • Thread starter Thread starter mobamoba
  • Start date Start date
M

mobamoba

I use Outlook 2007 on a single computer (i.e. not Exchange) and have
been using a VB macro for years without a problem. I rebooted today,
restarted Outlook and the macro is no longer working. Nothing in my
setup has changed at all. When I go to the VB Editor, the error I'm
getting is "Object not found." Considering I've changed absolutely
nothing, what, suddenly, isn't being found? I've posted the code
below - it's really a very simplistic macro designed to move email and
meeting requests from my inbox to a folder called Saved Mail. Thanks
in advance for any help because this problem is making me nuts!

Sub MoveMessage()

Dim onsMapi As Outlook.NameSpace
Dim oexpSource As Outlook.Explorer
Dim objItem As Object
Dim omapiDestination As Outlook.MAPIFolder
Dim lCount As Long


' Find the destination Folder 'Saved Mail'
Set onsMapi = Application.GetNamespace("MAPI")
Set omapiDestination = onsMapi.Folders.GetFirst.Folders("Saved
Mail")
' Get the current explorer
Set oexpSource = Application.ActiveExplorer
' Check each selection
For Each objItem In oexpSource.Selection
If TypeOf objItem Is Outlook.MailItem Or TypeOf objItem Is
Outlook.MeetingItem Then
' Move selection
objItem.Move omapiDestination
End If
Next

' Clean up
Set omapiDestination = Nothing
Set oexpSource = Nothing
Set onsMapi = Nothing
Set objItem = Nothing

End Sub
 
The line that references the "Saved Mail" folder is the one that's
screwing up:
Set omapiDestination = onsMapi.Folders.GetFirst.Folders("Saved Mail")

Basically, it can't find that folder even though it exists.

I created a new Saved Mail folder as a subfolder of the Inbox and was
able to get it to work using this:
Dim myInbox As Outlook.MAPIFolder
Set myInbox = onsMapi.GetDefaultFolder(olFolderInbox)
Set omapiDestination = myInbox.Folders("Saved Mail")

However, that wasn't really a solution. I don't want a subfolder to
my Inbox; I want Saved Mail as its own folder - and I can't figure out
how to make the macro find it. Any thoughts? Thanks!
 
The error is quite clear: the folder doesn't exist.

Check what GetFirst returns, and see if that's really what you expect it to
be.

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Wed, 24 Feb 2010 12:52:55 -0800 (PST) schrieb mobamoba:
 
The folder exists. I'm staring at it. I'm a VB beginner - how do I
find out what GetFirst is returning?
 
Use more variables, then you can work with the properties of an object. For
instance:

Dim F as MapiFolder
Set F=onsMapi.Folders.GetFirst
Msgbox F.FolderPath

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Thu, 25 Feb 2010 07:37:20 -0800 (PST) schrieb mobamoba:
The folder exists. I'm staring at it. I'm a VB beginner - how do I
find out what GetFirst is returning?

The error is quite clear: the folder doesn't exist.

Check what GetFirst returns, and see if that's really what you expect it to
be.

--
Best regards
Michael Bauer - MVP Outlook
  Manage and share your categories:
  <http://www.vboffice.net/product.html?pub=6〈=en>

Am Wed, 24 Feb 2010 12:52:55 -0800 (PST) schrieb mobamoba:
The line that references the "Saved Mail" folder is the one that's
screwing up:
Set omapiDestination = onsMapi.Folders.GetFirst.Folders("Saved Mail")
Basically, it can't find that folder even though it exists.
I created a new Saved Mail folder as a subfolder of the Inbox and was
able to get it to work using this:
Dim myInbox As Outlook.MAPIFolder
Set myInbox = onsMapi.GetDefaultFolder(olFolderInbox)
 Set omapiDestination = myInbox.Folders("Saved Mail")
However, that wasn't really a solution.  I don't want a subfolder to
my Inbox; I want Saved Mail as its own folder - and I can't figure out
how to make the macro find it.  Any thoughts?  Thanks!
On Feb 24, 3:13 am, "Michael Bauer [MVP - Outlook]" <[email protected]>
wrote:
At which row do you get the error?
--
Best regards
Michael Bauer - MVP Outlook
  Manage and share your categories:
  <http://www.vboffice.net/product.html?pub=6〈=en>
Am Tue, 23 Feb 2010 10:14:18 -0800 (PST) schrieb mobamoba:
I use Outlook 2007 on a single computer (i.e. not Exchange) and have
been using a VB macro for years without a problem.  I rebooted today,
restarted Outlook and the macro is no longer working.  Nothing in my
setup has changed at all.  When I go to the VB Editor, the error I'm
getting is "Object not found."  Considering I've changed absolutely
nothing, what, suddenly, isn't being found?  I've posted the code
below - it's really a very simplistic macro designed to move email and
meeting requests from my inbox to a folder called Saved Mail.  Thanks
in advance for any help because this problem is making me nuts!
Sub MoveMessage()
  Dim onsMapi As Outlook.NameSpace
  Dim oexpSource As Outlook.Explorer
  Dim objItem As Object
  Dim omapiDestination As Outlook.MAPIFolder
  Dim lCount As Long
  ' Find the destination Folder 'Saved Mail'
  Set onsMapi = Application.GetNamespace("MAPI")
  Set omapiDestination = onsMapi.Folders.GetFirst.Folders("Saved
Mail")
  ' Get the current explorer
  Set oexpSource = Application.ActiveExplorer
  ' Check each selection
  For Each objItem In oexpSource.Selection
    If TypeOf objItem Is Outlook.MailItem Or TypeOf objItem Is
Outlook.MeetingItem Then
      ' Move selection
      objItem.Move omapiDestination
    End If
  Next
  ' Clean up
  Set omapiDestination = Nothing
  Set oexpSource = Nothing
  Set onsMapi = Nothing
  Set objItem = Nothing
 
Back
Top