Track your unread items/total items count in Outlook on startup.

I added this to my Outlook macros [started with code for displaying all unread messages].

After selecting Alt-F11 and ThisOutlookSession [on the left sidebar], I selected "Application" and "Startup" [which is where this code is added.]

It append to a .csv file that can be opened in Excel. This is nice if you're attempting to get your inbox under control and want to track your progress.

Private Sub Application_Startup()
    On Error GoTo itfailed:
    ' I want to be able to catch up by reading all my unread messages
    Dim ns As Outlook.NameSpace
    Dim folder As MAPIFolder
    Dim item As Object
    Dim msg As MailItem
    Dim myfolder
 
    ' Open the inbox folder
    Set ns = Session.Application.GetNamespace("MAPI")
    Set folder = ns.GetDefaultFolder(olFolderInbox)
 
 
    myfolder = Environ$("USERPROFILE") & "my documents"
 
    myfile = "outlookunread.csv"
    Open myfolder & myfile For Append As 1
    Print #1, Strings.Format(Now, "Short Date") + " " + Strings.Format(Now, "Long Time") + "," + CStr(folder.UnReadItemCount) + "," + CStr(folder.Items.Count)
    Close 1
    Exit Sub
itfailed:
    MsgBox Err.Description, vbCritical, Err.Number
 
End Sub

VBScript to push files into an array based on a wildcard


Option Explicit
Dim gFSO
Dim dirListing
Dim fileName

set gFSO = CreateObject("Scripting.FileSystemObject")

dirListing = ListDir("c:??*d*")

If UBound(dirListing) = -1 then
Wscript.Echo "No files found."
Else
For Each fileName in dirListing
WScript.Echo FileName
Next
End If

'==============================================================================
' List a directory, with the last part of the directory being the path
'==============================================================================
Function ListDir (ByVal Path)
Dim fileRegex
Dim searchFolderName
Dim searchFolder
Dim searchFolderFiles
Dim fileName
Dim fileArray
Dim file

set fileRegex = New RegExp
If gFSO.FolderExists(Path) Then ' Path is a directory, list all files in path
searchFolder = Path
fileName = ""
Else
searchFolderName = gFSO.GetParentFolderName(Path)
fileName = gFSO.GetFileName(Path)
fileRegex.Global = True
fileRegex.Pattern = "."
fileName = fileRegex.Replace(fileName, ".")
fileRegex.Pattern = "?"
fileName = fileRegex.Replace(fileName, ".")
fileRegex.Pattern = "*"
fileName = fileRegex.Replace(fileName, ".*")
End If
With fileRegex
.Pattern = fileName
.IgnoreCase = True
.Global = False
End With

ReDim fileArray(1)
Dim fileCount : fileCount = 0

Set searchFolder = gFSO.GetFolder(searchFolderName)
Set searchFolderFiles = searchFolder.Files

For Each file in searchFolderFiles
If fileRegex.Test(file.Name) Then
If fileCount > UBound(fileArray) Then
ReDim Preserve fileArray(fileCount*2)
End If
fileArray(fileCount) = file.Path
fileCount = fileCount + 1
End If
Next
ReDim Preserve fileArray(fileCount - 1)
ListDir = fileArray
End Function

VBScript to convert timestamp to YYYYMMDD formatted string

I started with the code on this page.

Function FormatYYYYMMDD(timeStamp)

Dim dateMonth : dateMonth = DatePart("M", timeStamp)
Dim dateDay : dateDay = DatePart("D", timeStamp)
Dim dateYear : dateYear = DatePart("YYYY", timeStamp)
Dim dateString

dateString = dateYear

If dateMonth < 10 Then
dateString = dateString & "0" & dateMonth
Else
dateString = dateString & dateMonth
End If

If dateDay < 10 Then
dateString = dateString & "0" & dateDay
Else
dateString = dateString & dateDay
End If

FormatYYYYMMDD = dateString
End Function

Time since last boot (Windows, VBScript)

I don't remember where I found this, I was just happy to find code that did this.

 strComputer = "." ' Local computer 
set objWMIDateTime = CreateObject("WbemScripting.SWbemDateTime")
set objWMI = GetObject("winmgmts:\" & strComputer & "rootcimv2")
set colOS = objWMI.InstancesOf("Win32_OperatingSystem")
for each objOS in colOS
objWMIDateTime.Value = objOS.LastBootUpTime
Wscript.Echo "Last Boot Up Time: " & objWMIDateTime.GetVarDate & vbcrlf & _
"Time Since Last Boot: " & TimeSpan(objWMIDateTime.GetVarDate,Now) & _
" (hh:mm:ss)"
next

Function TimeSpan(dt1, dt2)
' Function to display the difference between
' 2 dates in hh:mm:ss format
If (isDate(dt1) And IsDate(dt2)) = false Then
TimeSpan = "00:00:00"
Exit Function
End If

seconds = Abs(DateDiff("S", dt1, dt2))
minutes = seconds 60
hours = minutes 60
minutes = minutes mod 60
seconds = seconds mod 60

if len(hours) = 1 then hours = "0" & hours

TimeSpan = hours & ":" & _
RIGHT("00" & minutes, 2) & ":" & _
RIGHT("00" & seconds, 2)
End Function