Updates from March, 2011 Toggle Comment Threads | Keyboard Shortcuts

  • tech0x20 11:52 am on March 10, 2011 Permalink | Reply
    Tags: , unread items, vba   

    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
    
     
  • tech0x20 9:56 am on July 10, 2008 Permalink | Reply  

    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
     
  • tech0x20 8:32 am on June 17, 2008 Permalink | Reply  

    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
     
    • rb 5:33 am on September 11, 2008 Permalink | Reply

      Excellent! You've just helped me out of a hole

      Here's the code to do the same for hours, mins and seconds:

      Function FormatHMS(timestamp)

      Dim dateHour : dateHour = DatePart("h", timeStamp)
      Dim dateMinute : dateMinute = DatePart("n", timeStamp)
      Dim dateSecond : dateSecond = DatePart("s", timeStamp)

      If dateHour < 10 Then
      timeString = timeString & "0" & dateHour
      Else
      timeString = timeString & dateHour
      End If

      timeString = timeString & ":"

      If dateMinute < 10 Then
      timeString = timeString & "0" & dateMinute
      Else
      timeString = timeString & dateMinute
      End If

      timeString = timeString & ":"

      If dateSecond < 10 Then
      timeString = timeString & "0" & dateSecond
      Else
      timeString = timeString & dateSecond
      End If

      FormatHMS = timeString

      End Function

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel
%d bloggers like this: