PDA

View Full Version : Outlook Folder Path



tg23
04-19-2019, 04:34 PM
Goo day all

I have this problem pointing the correct outlook subfolder path, it gives me "run time error 13".

The sub folder is "CHHIEW\Hong\Report", it's outside of inbox folder, have tried many times changing the "/" and "" but still did'nt work, anyone got any idea how to fix this?

Thank you for your help


Private Sub Application_Startup()


Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim olFolder As Outlook.MAPIFolder
Dim GetFolder As Outlook.MAPIFolder
Dim objFolder As Outlook.MAPIFolder


Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder("\\CHHIEW\Hong\Report")

Set Items = Inbox.Items

End Sub

gmayor
04-19-2019, 09:09 PM
I don't think it is possible to set the inbox in this way, however to get the folder, you would need code like the following. The message boxes are purely for testing.


Sub Test()
Dim olNS As NameSpace
Dim olStore As Store
Dim olItem
Dim olFolder As Folder
Dim bFound As Boolean
Set olNS = Application.GetNamespace("MAPI")
For Each olStore In olNS.Stores
If olStore.DisplayName = "CHHIEW" Then
bFound = True
Exit For
End If
Next olStore
If Not bFound Then
MsgBox "The store CHHIEW was not found"
GoTo lbl_Exit
End If
Set olFolder = olStore.GetRootFolder.folders("Hong").folders("Report")
MsgBox olFolder.FolderPath
lbl_Exit:
Exit Sub
End Sub

tg23
04-20-2019, 02:38 AM
Hi Gmayor,
Thanks for your help. yes i can see the msgbox displayed the folder path, but how can i incorporate that path in my script?

sorry i am newbie with limited programming knowledge to outlook vba.

Thanks

gmayor
04-20-2019, 08:17 PM
The message box is there to show that the code works. olFolder is the folder related to that path.

tg23
04-21-2019, 08:01 PM
Gmayor,
Thank you so much. will explore and figure out this.

Thanks