Help - VB Macro no longer work

Status
Not open for further replies.
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
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
At which row do you get the error?

Best regards

Michael Bauer

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

> End Sub
 
M

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 " <m...@mvps.org
wrote:
> At which row do you get the error?

> > Best regards
> Michael Bauer
>

> <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

>
> > End Sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
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

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 " <m...@mvps.org
> wrote:
> > At which row do you get the error?
>

>> > > Best regards
> > Michael Bauer
> >

> > <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

> >
> >> End Sub
 
M

mobamoba

The folder exists. I'm staring at it. I'm a VB beginner - how do I

find out what GetFirst is returning?

On Feb 25, 4:23 am, "Michael Bauer " <m...@mvps.org
wrote:
> 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
>

> <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 " <m...@mvps.org
> > wrote:
> >> At which row do you get the error?

>
> >> > >> Best regards
> >> Michael Bauer
> >>

> >> <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 errorI'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 objItemIs
> >>> 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
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
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

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?

> On Feb 25, 4:23 am, "Michael Bauer " <m...@mvps.org
> wrote:
> > 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
> >

> > <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 " <m...@mvps.org
>>> wrote:
> >>> At which row do you get the error?

> >
> >>> > >>> Best regards
> >>> Michael Bauer
> >>>

> >>> <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

> >
> >>>> End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
S HTML to Plain Text Macro - Help Outlook VBA and Custom Forms 1
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
C Newbie needs help with Outlook Macro Outlook VBA and Custom Forms 3
A newb outlook macro help Outlook VBA and Custom Forms 1
E Help with macro to answer and delete calendar requests? Outlook VBA and Custom Forms 5
A Help creating macro for conditional formatting settings Using Outlook 8
S Help macro Outlook VBA and Custom Forms 1
C Help with a Macro to move emails to a different PST data file Using Outlook 4
F Help with Outlook 2007 Macro Please! Using Outlook 4
R VBA Macro to VBScript in a form- Help Please! Using Outlook 10
S Outlook macro help Using Outlook 10
P Please Help me Create a Macro ! Using Outlook 2
D Help with simple macro - looping though all emails in my inbox Using Outlook 3
S Macro help Using Outlook 4
S Outlook 2003: Help with setting up a macro to reply to selected emails Using Outlook 2
S MAcro - Need help in getting the recipients in to filed / cc field toput in an array Outlook VBA and Custom Forms 4
L Help for writing an Outlook 2007 macro Outlook VBA and Custom Forms 7
V Outlook macro help please Outlook VBA and Custom Forms 23
e_a_g_l_e_p_i Has nobody used Office 2021 enough to help me or have you given up on me.......lol Using Outlook 1
X Open Hyperlinks in an Outlook Email Message (Help with Diane's solution) Outlook VBA and Custom Forms 3
L Help connecting to hosted exchange server 2016 Using Outlook 0
B Seeking help with Outlook rule Using Outlook 2
D Need help with MS Authenticator Using Outlook 4
I Outlook for Mac 2019 using on desktop and laptop IMAP on both need help with folders Using Outlook 1
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
S.Champ Please help? I've imported a random workcalendar I dont even know who's. Can I undo it? and then I need to re-sync the google one again. Its a mess:( Using Outlook 2
e_a_g_l_e_p_i Outlook 2010 Help setting up Gmail account in Outlook 2010 Using Outlook 3
Y Filter unread emails in a search folder vba help Outlook VBA and Custom Forms 0
L Need help modifying a VBA script for emails stuck in Outbox Outlook VBA and Custom Forms 6
F Microsoft Outlook Connector 14.0.6123.5001 - Help! Using Outlook 6
witzker Pls help to change the code for inserting date in Ol contact body Outlook VBA and Custom Forms 5
R Disable conversation thread from replying of recipients in the same subject. Please help Using Outlook 0
R seperate read layout to design in outlook 2016..Help!! Outlook VBA and Custom Forms 3
O Help .. got lost ... installing Office like 2016 Using Outlook 5
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
Marc2019 Need help please! Cannot Setup my outlook email account on my Mac Outlook 2011 Using Outlook.com accounts in Outlook 2
L Attachment saving and tracking - PLEASE help! Outlook VBA and Custom Forms 5
I Help with dates in task list. Using Outlook 5
C need help setting up outlook first time Using Outlook 1
K To do bar help Using Outlook 8
M Help sending email but removing signature via VBA Outlook VBA and Custom Forms 5
S help with outlook scripting Outlook VBA and Custom Forms 4
EmelineGueguen Help to understand the problem of work Using Outlook 1
N Outlook Forms Help Outlook VBA and Custom Forms 2
N Need help syncing contacts to iPhone X Using Outlook 8
broadbander Needing help with reply/reply all while keeping attachments and adding a new CC recipient. Outlook VBA and Custom Forms 5
J Help! My contacts have disappeared. Using Outlook 5

Similar threads

Top