Originally Posted by
OfirMarco
Hi Again,
I have tried the explanations in the link you attached.
It makes sense but still something is not working right.
Outlook - folder MSP.jpg
As you can see, when i debug and passing this line of code, it still shows the variable as "Nothing".
Can it be something like i am using the wrong type of variable in the declaration?
How should the item be defined? is it calendar type, item type? not sure why nothing is working.
The Application here is MS Project not Outlook.
You are setting newCalFolder to the items in the folder.
The root problem is the misuse of On Error Resume Next.
Sub Export_Selection_To_Resources_OL_Calendar_Appointments_From_Other_Account()
Dim myOLApp As Outlook.Application
Dim myObj As Object
Dim myItem As Outlook.AppointmentItem
Dim Ns As Outlook.NameSpace
Dim myDestFolder As Outlook.Folder
' Errors are hidden
' Failure is almost guaranteed when misused
'On Error Resume Next
Set myOLApp = CreateObject("Outlook.Application")
' Hidden failure point: Application = MS Project
'Set Ns = Application.GetNamespace("MAPI")
Set Ns = myOLApp.GetNamespace("MAPI")
Set myDestFolder = Ns.GetDefaultFolder(olFolderCalendar)
Set myDestFolder = myDestFolder.Folders("MSP")
' If this is not the default account then
'Set myDestFolder = Ns.Folders("Ofir... / mailbox name / email address of the other account")
'Set myDestFolder = myDestFolder.Folders("Calendar")
'Set myDestFolder = myDestFolder.Folders("MSP")
' This more flexible format can also be used for the default account
' Hidden failure point:
'For Each myTask In ActiveSelection.Tasks
For Each myObj In ActiveExplorer.Selection
' A selection (or folder) could contain any type of item
If myObj.Class = OlTask Then
'Set myItem = myOLApp.CreateItem(olAppointmentItem)
Set myItem = myDestFolder.items.Add(olAppointmentItem)
With myItem
.Subject = myObj.Subject
.Save
End With
End If
Next myObj
Set ActiveExplorer.CurrentFolder = myDestFolder
MsgBox "All selected tasks exported to resources Outlook Calendar as appointments", vbOKOnly, "Export Completed"
End Sub