Jonas Offersen

New Member
Joined
Feb 13, 2018
Messages
14
Hi everyone, I'm okay with vba and excel, but I am a complete newbie with outlook.

I am trying to copy alle outlook.items from one calendar to another using this code. The copying works as intended but I get an error message when I try to use "if one item = the other item"... Does anyone here know what I am dong wrong?

All help is much appreciated!

PS! (I was not sure which forum to post this in, did I get it right? :p)
Code:
    For Each i In Outlook.Session.GetFolderFromID(TextBoxOrigin.Text).Items
        If (Outlook.Session.GetFolderFromID(TextBoxDestination.Text).Items.Count <> 0) Then [COLOR=#00ff00]'if there is no items in the destination folder[/COLOR]
            For Each i2 In Outlook.Session.GetFolderFromID(TextBoxDestination.Text).Items
                If (i2 = i) Then [COLOR=#00ff00]'if origin item is in the destination folder < this is where i get the error.[/COLOR]
                    exist = True
                End If
            Next
        Else
            exist = False
        End If
        
        If exist = False Then
            Dim myCopiedItem As Outlook.AppointmentItem
            Dim myFolder As Outlook.Folder
            
            Set myFolder = Outlook.Session.GetFolderFromID(TextBoxDestination.Text)
            Set myCopiedItem = i.Copy
            myCopiedItem.Move myFolder
        End If
    Next
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Using is instead of = removes the error, the whole function now works however the check always return false, even when it should return true... x.X

Code:
If (i2 Is i) Then [COLOR=#00ff00]'if origin item is in the destination folder < this is where i get the error.[/COLOR]
      exist = True
End If
 
Last edited:
Upvote 0
Are the item subjects unique? You will have to compare some item property.


Code:
If CStr(i2.Subject) = CStr(i.Subject) Then
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top