VBA Outlook

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? :stickouttounge:)
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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,223,774
Messages
6,174,453
Members
452,565
Latest member
curtoliver68

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