Hi,

I have a VBA script set up in outlook which counts how many emails are in the specific inboxed or sub folders. I have set it up to also create a CSV file and then continue to update every minute but this is not happening. My macro is below, can someone advise what is going wrong

Sub timer()

TimeToRun = Now + TimeValue("00:01:00")
Application.OnTime TimeToRun, "stuff"

End Sub


Sub stuff()

Dim objOutlook As Object, objnSpace As Object, mailboxFolder As MAPIFolder, mailboxFolder As MAPIFolder, mailboxFolder As MAPIFolder
Dim mailbox As Integer, emailcount As Integer, emailCount As Integer
' Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = GetNamespace("MAPI")

On Error Resume Next
Set objFolder = objnSpace.Folders("Mailbox").Folders("Inbox").Folders("Sub folder")
If Err.Number <> 0 Then
Err.Clear
MsgBox "No such folder."
Exit Sub
End If

EmailCount = objFolder.Items.Count

On Error Resume Next
Set objFolder = objnSpace.Folders("Mailbox").Folders("Inbox")
If Err.Number <> 0 Then
Err.Clear
MsgBox "No such folder."
Exit Sub
End If

EmailCount = objfolder.Items.Count

On Error Resume Next
Set objFolder = objnSpace.Folders("mailbox").Folders("Inbox")
If Err.Number <> 0 Then
Err.Clear
MsgBox "No such folder."
Exit Sub
End If

EmailCount = objFolder.Items.Count

Dim csvOutput As String

' Create counts string:
csvOutput = ""
csvOutput = "Emailfolder,Emailfolder,emailfolder " & vbNewLine & mailboxCount & "," & mailboxCount & "," & mailboxCount

Dim fso As Object
Dim fo As Object

Set fso = CreateObject("Scripting.FileSystemObject")
Set fo = fso.CreateTextFile("C:\test\test\test.csv")
fo.Write csvOutput
fo.Close

Set fo = Nothing
Set fso = Nothing
Set mailboxFolder = Nothing
Set mailboxFolder = Nothing
Set mailboxFolder = Nothing
Set objnSpace = Nothing

Call timer

End Sub

if anyone could help me that would be great,

thanks