Avatar of CCG3
CCG3Flag for United States of America asked on

Automaticly MOVE event from one calendar to another...

We are running Outlook 2007 SP2, I have a user that has two different calendars and when certain events come in (Live Meeting Requests) she wants to move the item from one calendar to the other (NOT COPY). Every time I set this up as a rule it will create a new event on the 2nd calendar but it won't automatically remove the event on the other calendar.

Can anyone suggest a way to do this other than manually moving it? This is a training manager so the volume of events we are talking about is too much to manually do it all the time.

Thanks for any help that you can provide!
OutlookMicrosoft ApplicationsProgramming

Avatar of undefined
Last Comment
David Lee

8/22/2022 - Mon
David Lee

Hi, CCG3.

I believe I can do it with a bit of scripting.  If that's an option, then I can post the script and instructions on how to use it.
ASKER
CCG3

Thanks for your reply BDF, Yes that is an option if you can post that I would love to try it. Thanks so much for helping me with this!
ASKER CERTIFIED SOLUTION
David Lee

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
CCG3

Reading through this, will it move everything? Is there a way for it to pick out something from the invite and move it based on that?

If her boss or someone sends her an invite (regular meeting request or Live Meeting request) she wants it to go on her regular calendar. But anytime there is a Live Meeting request from her trainers then this is when we would want this to kick in.

Just trying to make sure that we are on the same page before I put this in place. Of course I will test it on my PC before I go live with it on hers.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
David Lee

That's what the IF statement on line 13 does.  It ignores items that don't have a certain keyword or phrase in the subject.  It there's nothing unique in the subject that we can key on, then you'll have to identify something about these items that is unique and we'll see if we can use it.
ASKER
CCG3

Hey BDF, thanks for sharing that it really works well with just one slight issue...

I put that in place and tweaked what you suggested and got a few successful tests. However, it seems to copy it as soon as it comes in and then it puts another copy on the same folder as soon as I click accept. Is there a way to only do it once?
David Lee

I think I can force it to automatically accept those items.  Would that work?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
CCG3

Yes I think would work fine. Thank you!
David Lee

Replace the subroutine olkCalendar_ItemAdd with the one below.  It automatically accepts the appointments as the arrive.
Private Sub olkCalendar_ItemAdd(ByVal Item As Object)
    'On the next line change Testing to some text that is unique to these appointments'
    If InStr(Item.Subject, "Testing") Then
        Item.Respond olMeetingAccepted
        'On the next line enter the path to the target calendar'
        Item.Move OpenOutlookFolder("Mailbox - Doe Jane\My Other Calendar")
    End If
End Sub

Open in new window

ASKER
CCG3

I tried this but I get an error when it his the Item.Respond line....

Run-tim error '-2147221241(80040107)': The operation failed.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
David Lee

This was for a newly received meeting request, right?
ASKER
CCG3

Yes. I had someone send me a new one. I did have an older request with the same name but that is going to happen if we are conditioning on the subject line. Right?
David Lee

Are there any other rules which might have interfered with this one?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
CCG3

No. I don't have any rules for requests and none that look for subject or any that look for something from the user that sent that request.
David Lee

Then I don't see how this can fail.  I tested before posting and it worked.  I've automatically accepted meetings in other scripts and that has always worked.  I don't see any reason why it should fail here.
ASKER
CCG3

I am still testing it. If I run it with no breakpoints it fails. If I put a breakpoint in and F8 through it then it seems to work fine. If I then run it with a break point on the line Private Sub olkCalendar_ItemAdd(ByVal Item As Object) and F5 through it instead of F8 then it seems to be looping through this routine twice. Could that be the problem?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
David Lee

Hmmm.  That might be it I suppose, although I don't know why I wouldn't have run into the same situation when I tested.  

Try this version.  It checks the item to see if it's already been accepted.  If it hasn't then it takes action.  If it has been accepted, then it does nothing.
Private Sub olkCalendar_ItemAdd(ByVal Item As Object)
    'On the next line change Testing to some text that is unique to these appointments'
    If InStr(Item.Subject, "Testing") Then
        If Item.ResponseStatus <> olResponseAccepted Then
            Item.Respond olMeetingAccepted
            'On the next line enter the path to the target calendar'
            Item.Move OpenOutlookFolder("Mailbox - Doe Jane\My Other Calendar")
        End If
    End If
End Sub

Open in new window

ASKER
CCG3

Same thing. Could this be a timing issue? Is there a way to pause/wait in the code before the End Sub or right after the Item.Move?
ASKER
CCG3

Any suggestions on how to stop this from looping through that routine more than one time?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
David Lee

Apologies.  I could have sworn I'd replied.  I doubt that it's a timing issue.  Yes, we can insert a pause, but I doubt that'll help.  Moving the End Sub would not do anything.  If you want to try the pause, then add the declaration below to the top of ThisOutlookSession in the code window.  After the Item.Move line insert

Sleep 1000

This will cause the code to pause for 1 second.  If you want a longer pause then replace 1000 with the number of seconds times 1,000.


Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Open in new window

ASKER
CCG3

When I put that declaration in the top of the code window I get this error when I open and close...

Compile error:
Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules.


If you don't think it is a timing issue then can we drop a variable in there and turn it on/off to make is skip the routine? And the reset it once it finishes?
David Lee

Try adding the word Private before Declare.
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
CCG3

I added the work Public before Declare and I am still getting the same error when I open/close outlook. Are we working with the same Outlook versions (2007)? Do I have something setup incorrectly?
David Lee

Private not Public.
ASKER
CCG3

Yes I had Public instead of Private.

I added that and you are correct, it still does the same thing so the delay didn't fix it. it is crazy. I can F8 through it with no problems but if I F5 it fails.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
David Lee

I can't think of any logical explanation for that behavior.  I don't doubt that's what's happening, I'm just a at a loss to understand how or why.  When you step through the code using F8 does code loop through the same procedure twice?
ASKER
CCG3

When I step through (F8), it gets to the end sub and just stops like you would expect it to. But if I F5 through it then it comes right back to that routine and if I press F5 again then I get the error. Could be be because of where I have by second calendar? Maybe once it is moved it prompts the code to run again?
David Lee

The code is only watching your default calendar.  The move removes the item from the default and moves it to the secondary calendar.  It's impossible for the code to be triggered by the add to the secondary calendar.  Try this version.  This disables monitoring of the default calendar until the process is complete.
Private Sub olkCalendar_ItemAdd(ByVal Item As Object)
    'On the next line change Testing to some text that is unique to these appointments'
    If InStr(Item.Subject, "Testing") Then
        If Item.ResponseStatus <> olResponseAccepted Then
            Set olkCalendar = Nothing
            Item.Respond olMeetingAccepted
            'On the next line enter the path to the target calendar'
            Item.Move OpenOutlookFolder("Mailbox - Doe Jane\My Other Calendar")
            Set olkCalendar = Session.GetDefaultFolder(olFolderCalendar).Items
        End If
    End If
End Sub

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
CCG3

Thanks BDF! Now I think we are on to something. I think it was switching the current calendar from my default to the secondary when the item was moved and that was causing the issue. My first tests worked much better with no errors so I will have to do more testing tomorrow or the next day.

Is there a way to use a wild card in the subject statement so it doesn't have to be the exact text but they an append more descriptive data to it? and I am guessing in that If instr statement I can do an or statement right? If so, is this the correct way to do it?

 If InStr(Item.Subject, "Test") OR InStr(Item.Subject, "Test 1") OR InStr(Item.Subject, "Test 2) Then
David Lee

Yes, you can string together multiple InStr functions with or's.  
ASKER
CCG3

This looks to be working great! Thanks for all of your help BDF!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
David Lee

You're welcome.  Glad I could help.