View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Andy Andy is offline
external usenet poster
 
Posts: 38
Default Copy item from Outlook to folder via Excel

GetFolder explores the folder structure and returns the last folder name via:

"Public Function GetFolder(strFolderPath As String) As Object

Dim objApp As Object
Dim objNS As Object
Dim colFolders As Object
Dim oFolder As Object
Dim arrFolders() As String
Dim i As Long
On Error Resume Next

strFolderPath = Replace(strFolderPath, "/", "\")
arrFolders() = Split(strFolderPath, "\")

Set objApp = GetObject("", "Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set oFolder = objNS.Folders.Item(arrFolders(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(arrFolders)
Set colFolders = oFolder.Folders
Set oFolder = Nothing
Set oFolder = colFolders.Item(arrFolders(i))
If oFolder Is Nothing Then
Exit For
End If
Next
End If

Set GetFolder = oFolder
Set colFolders = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Function"


I've tried "FileCopy Source:=oFolder & objMsg, Destination:=mypath & objMsg" but still no file can be found. Interestingly it shows "File not found" and if i change oFolder & objMsg to oFolder & "\" & objMsg it shows "Path not found". I guessed that there is a fault with the file name but it shows as it should through objmsg...

The filepath is "Public Folders\All Public Folders\Queue\New Template" and oFolder returns "New Template" ObjMsg returns the correct filename, mypath returns the correct G drive path.

I've tried variations of the below with no joy, and I can't think of an alternative to Dir as that is only for windows file structure, not outlook as far as I know?

FileCopy Source:="Public Folders\All Public Folders\Queue\New Template\" & objMsg, Destination:=mypath & objMsg"