VBA Code No Longer Works

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

VBA Code No Longer Works

Post by jstevens »

I'm having a challenge setting a variable with Outlook VBA. The code use to work and the only thing I can think of that may be different is a MS update. The error messages is "Run-time error 13: type mismatch"

Code: Select all

Dim Folder As Outlook.Folder

'MsgBox Application.Session.Folders("TS_Gmail").Folders("Inbox")          'Msgbox returns the variable. In this case "InBox"
Set Folder = Application.Session.Folders("TS_Gmail").Folders("Inbox")   'Code fails here
Your thoughts are appreciated.
Regards,
John

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA Code No Longer Works

Post by HansV »

Strange - it works for me if I replace TS_Gmail with a mailbox in my Outlook.
- What happens if you replace TS_Gmail with the name of another mailbox?
- What happens if you change the name of the variable to objFolder?
- What happens if you declare the variable as Object instead of as Outlook.Folder?
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: VBA Code No Longer Works

Post by jstevens »

Hans,

Declaring the variable as Object instead of as Outlook.Folder worked.

Thanks for the suggestions.
Regards,
John