using Folders.Count in Excel Vba

Status
Not open for further replies.

Mark Scholes

Member
Outlook version
Outlook 2013 32 bit
Email Account
Office 365 Exchange
Hi,

I am using outlook 2013 (32 bit) and I have this piece of code in my Excel spread sheet. It finds a e-mail in a folder opens it and extracts the spread sheet. The part of the code which finds the folder now doesn't work, it did work in outlook 2010 (32Bit)

Set mynamespace = Outlook.Application.GetNamespace("MAPI")
' Set the Source to the mail Inbox folder for AFMA Green data
' Set the Target to the mail sub folder for archiveing
Set SourceFolder = mynamespace.Folders("Risk Quantitative")
' Find the Inbox
iLoopcounter = 1
Do Until iLoopcounter > SourceFolder.Folders.Count
If SourceFolder.Folders(iLoopcounter) = "Inbox" Then
Set SourceFolder = SourceFolder.Folders(iLoopcounter)
Exit Do
End If
iLoopcounter = iLoopcounter + 1
Loop

When you run ? SourceFolder.Folders.count you should get 13, I now only get 0 and so the next piece of code fails
' Find AFMA Green
iLoopcounter = 1
Do Until iLoopcounter > SourceFolder.Folders.Count
If SourceFolder.Folders(iLoopcounter) = "AFMA Green" Then
Set SourceFolder = SourceFolder.Folders(iLoopcounter)
Exit Do
End If
iLoopcounter = iLoopcounter + 1
Loop

To add to the problem I have Four mailboxes

Any thought would be great
Mark Scholes
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I added debug prints after the loop counter is set, and after each increment. I get:
1 Start
2 Inbox
14afma green

The only change I made was to change the mailbox name and the folder names to ones that exist here.
 

Mark Scholes

Member
Outlook version
Outlook 2013 32 bit
Email Account
Office 365 Exchange
I have several e-mail accounts in the same profile. If I have only one email account in the profile it works fine.
You get a error 'Run-time error '440': Array index out of bounds.' which is reasonable as the line reads 'Set TargetFolder = SourceFolder.Folders(1)'
 

Mark Scholes

Member
Outlook version
Outlook 2013 32 bit
Email Account
Office 365 Exchange
Silly thought, Where do I fine which version of outlook 2013 I have and what is the latest version. IT update out software and we don't use Microsoft update, and I don't know if it up to date.

Thanks for your reply
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I'd don't think the version matters - the code should work in all versions but you can look in File, Office account.

The problem is that 'Set TargetFolder = SourceFolder.Folders(1)' is having problems finding the right folders, I'm sure its related to the # of mailboxes, although I have 3 + a bunch of shared mailboxes and it worked for me.
 

Mark Scholes

Member
Outlook version
Outlook 2013 32 bit
Email Account
Office 365 Exchange
I have updated to the latest version and this problem has gone. I have no idea if it was the Office 2013 updates or the Windows 8.1 updates that they did at the same time
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I wouldn't want to even guess which updates fixed it. :)
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Can i apply mail rules to inbox sub folders using VBA Outlook VBA and Custom Forms 2
N Using Categories & Search Folders with multiple accounts Using Outlook 4
D folders are missing using imap outlook 2007 Using Outlook 1
D export contacts in Outlook 2003 using Windows 7 - no folders Using Outlook 10
P move folders in outlook using vba Outlook VBA and Custom Forms 1
pcunite Outlook 2019/O365 Build 13127.20408 errors when using MAPI calls Using Outlook 1
B Change Font and Font size using VBA Outlook VBA and Custom Forms 9
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
X Using Outlook 2013 and Outlook 365 Using Outlook 1
A Going to folder using shortcuts Using Outlook 3
A Outlook replies not using "delivered to" address in From Using Outlook 1
Terry Sullivan E-Mails Sent Using a Group Box Result in 70 Kickbacks Using Outlook 5
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
K Using Outlook 2016 to draw Using Outlook 1
O Outlook 365 - suddenly unable to send using Gmail POP3 Using Outlook 10
N Disable Auto Read Receipts sent after using Advanced Find Using Outlook 4
G Outlook 2016 sync contacts directly between phone and computer using outlook 2016 Using Outlook 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
O Save attachments using hotkey without changing attributes Outlook VBA and Custom Forms 1
J Add an Attachment Using an Array and Match first 17 Letters to Matching Template .oft to Send eMail Outlook VBA and Custom Forms 2
A Edit subject - and change conversationTopic - using VBA and redemption Outlook VBA and Custom Forms 2
A Using or not using apostrophes in search terms has this changed? Using Outlook 0
O Office 365 using POP3 on both laptop and desktop Using Outlook 0
M Using field names to capture a data element Using Outlook 0
B Vba to monitor time to respond to emails using a shared mailbox Outlook VBA and Custom Forms 5
B Looking to get the Recipient email address (or even the "friendly name") from an email I am replying to using VBA Outlook VBA and Custom Forms 4
D Using a VBA Custom Form to Send Reoccurring Email Upon Task Completion Outlook VBA and Custom Forms 4
Z Adding dropdown list using custom form Outlook VBA and Custom Forms 7
O Using .OST and .PST mail thru different providers Using Outlook 5
N Open & Save VBAProject.Otm using VBA Code Outlook VBA and Custom Forms 1
D Remove text in subject using VBA Outlook VBA and Custom Forms 4
P How to export voting results using VBA? Outlook VBA and Custom Forms 2
E Using the Like operator properly Outlook VBA and Custom Forms 1
R Using "check for duplicates" for existing contacts Using Outlook 2
S Find a cell value in excel using outlook vba Using Outlook 1
N Using email notification to update calendar events? Outlook VBA and Custom Forms 4
S Macro using .SendUsingAccount only works the first time, after starting Outlook Outlook VBA and Custom Forms 4
C Sync Calendars using WiFI Using Outlook 3
A Capturing Send Variables without using Application_ItemSend in ThisOutlookSession Outlook VBA and Custom Forms 8
L Using alpha numeric in email address Using Outlook 5
Sabastian Samuel HOW DO I FORWARD AN EMAIL WITH MACRO using an email that in the body of another email Outlook VBA and Custom Forms 3
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
D Print Attachments only in selected emails using a macro Outlook VBA and Custom Forms 3
B query outlook using vba Outlook VBA and Custom Forms 13
M Using conditional formatting on a shared calendar with categories Using Outlook 6
e_a_g_l_e_p_i A question about installing office 2013 Pro and using my .pst from office 2010 Using Outlook 12
A Forward Outlook Email by Filtering using Macro Rule Outlook VBA and Custom Forms 44
O How to paste website content using a specific font and removing URLs Using Outlook 2
P Replying to calendar item using VBA Outlook VBA and Custom Forms 4
N Export details to a excel spreadsheet using macros Using Outlook 0

Similar threads

Top