VBA - Outlook Public Mail Folder
Hej,Jeg forsøger at gemme vedhæftede filer og flytte en mail i en public folder..
det spiller ikke - pt får jeg fejlen "..an object could not be found" i linjen "set FldIn = Topfolder1.Folders(PubFolderInbox)
jeg har følgende kode:
Option Explicit
Sub SaveFilesPublicFolder()
Dim App As Outlook.Application
Dim NS As Outlook.NameSpace
Dim FldIn As Outlook.MAPIFolder
Dim FldSub As Outlook.MAPIFolder
Dim TopFolder As Outlook.MAPIFolder
Dim TopFolder1 As Outlook.MAPIFolder
Dim Insp As Outlook.Inspector
Dim Itm As Outlook.MailItem
Dim Att1 As Outlook.Attachment
Dim Att As Outlook.Attachments
Dim Temp As String
Dim Year As String
Dim Mon As String
Dim Day As String
Dim FilNavn As String
Dim PubFolder As String
Dim PubFolderInbox As String
Dim PubFolderReports As String
PubFolderInbox = "\\Public Folders - personalmail@mail.dk\All Public Folders\Back Office\ABC\inbox"
PubFolderReports = "\\Public Folders - personalmail@mail.dk\All Public Folders\Back Office\ABC\Reports"
Set App = CreateObject("Outlook.Application")
Set NS = App.GetNamespace("MAPI")
Set TopFolder1 = NS.Folders("personalmail@mail.dk")
Set FldIn = TopFolder1.Folders(PubFolderInbox)
'NS.Folders ("publicmail@mail.dk")
'Set FldIn = NS.GetDefaultFolder(olFolderInbox)
Set TopFolder = NS.Folders("publicmail2@mail.dk")
Set FldSub = TopFolder.Folders("TEST")
Set Insp = Application.ActiveInspector
For Each Itm In FldIn.Items
If Left(Itm.Subject, 15) = "TESTSUBJECT" Then
'Itm.Attachments.Count <> 0 Then
'date from filename
For Each Att1 In Itm.Attachments
Year = Mid(Att1.FileName, 21, 4)
Mon = Mid(Att1.FileName, 17, 2)
Day = Mid(Att1.FileName, 19, 2)
'Saves attachment
Itm.Attachments(1).SaveAsFile "I:\ " & Mon & Day & Year & ".xlsx"
Next
'End If
'Moves mail to inbox
Itm.Move FldSub
MsgBox "Attachments saved and mail moved to subfolder: Test", vbOKOnly
End If
Next
End Sub