Thursday 26 July 2012

A bit of script to export emails to excel file




A bit of script to export emails to excel files:
 
<pre class='brush: vb'>
Dim appExcel As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
Dim rng As Excel.Range
Dim strSheet As String
Dim strPath As String
Dim intRowCounter As Integer
Dim intColumnCounter As Integer
Dim msg As Outlook.MailItem
Dim nms As Outlook.NameSpace
Dim fld As Outlook.MAPIFolder
Dim itm As Object
strSheet = "OutlookItems6.xlsx"
strPath = "C:\Test\"
strSheet = strPath & strSheet
Debug.Print strSheet  'Select export folder
Set nms = Application.GetNamespace("MAPI")
Set fld = nms.PickFolder  'Handle potential errors with Select Folder dialog box.
    If fld Is Nothing Then
        MsgBox "There are no mail messages to export", vbOKOnly, "Error"
        Exit Sub
    ElseIf fld.DefaultItemType <> olMailItem Then
    ElseIf fld.Items.Count = 0 Then
    End If  'Open and activate Excel workbook.

Set appExcel = CreateObject("Excel.Application")

'appExcel.Workbooks.Open (strSheet)
Set wkb = appExcel.Workbooks.Add()


wkb.Activate


Set wks = wkb.Worksheets.Add()
wks.Activate

appExcel.Application.Visible = True  'Copy field items in mail folder.
   
    For Each itm In fld.Items
        intColumnCounter = 1
        Set msg = itm
        intRowCounter = intRowCounter + 1

        Set rng = wks.Cells(intRowCounter, intColumnCounter)
        rng.Value = msg.To
        intColumnCounter = intColumnCounter + 1
        rng.Value = msg.SenderEmailAddress
        rng.Value = msg.Subject
        rng.Value = msg.SentOn
        rng.Value = msg.ReceivedTime
        rng.Value = msg.Body

    Next itm

   
wkb.SaveAs (strSheet)
wkb.Close
   
Set appExcel = Nothing
Set wkb = Nothing
Set wks = Nothing
Set rng = Nothing
Set msg = Nothing
Set nms = Nothing
Set fld = Nothing
Set itm = Nothing
Exit Sub

ErrHandler:
If Err.Number = 1004 Then
    wkb.Close
    MsgBox strSheet & " doesn't exist", vbOKOnly, _
    Error
Else
    wkb.Close
    MsgBox Err.Number & "; Description: ", vbOKOnly
End If

</pre>

Friday 20 July 2012

Malodic Banjo Arranger Part 1

As part of a push to develop my skills further and raise my visibility within the coding community, I decided to startup a number of open source projects and hopefully leverage existing source on CodePlex, GitHib etc... to take the pain out of getting a project up and running.

Being a part time musician and a long term fan of the Banjo, one of the projects I have begun working on is a Melodic Banjo tablature Arranger implemented either as self contained application or plugin module for an existing  tablature/music scoring application.

A question some may be asking is why does the world need a Melodic Banjo tablature Arranger?  Or, what the heck is Melodic Banjo?  I don't want to go into too much detail as the this Wikipedia article explains things very well but its basically a way of playing a melody on the Banjo which encourages as few sequential notes being played on the same string as possible resulting in an overall un-interupted series of ringing notes.

It is a great style however it is quite time consuming working out the best way to play a given melody in this style as there may be many numbers of ways to play the same note (as with most stringed instruments) but depending on the order of the notes, the current musical phrase and where you last note was fretted it is not immediately obvious what fret & string the next note should be played on.

This I am attempting to help by providing a way to process a MIDI file, pick a track and calculate the best way to arrange the notes in this banjo style.

The second phase would be to allow experimentation of the calculated arrangement allowing the user to fix notes they like and recalculate the remaining 'un-fixed' arranged notes.  I would also like to include the ability to possible open tunings which can be dynamically changed

Finally, the third phase (which is kind of running parallel to the previous two phases) is to wrap the project up in a plug-in to extend an existing app or pull together open source code to display/print the arranged tabliture in a usable format and allow the interaction with the arrangement mentioned in phase 2.

I have had an initial play with nAudio which is great at abstracting phrasing of MIDI files however I have been pleasantly surprised at the development of JavaScript music Score/Midi parses projects on Git Hub:

https://github.com/arthurlenoir/DionyScore
https://github.com/GregJ/HTML5-Guitar-Tab-Player
https://github.com/cwilso/Standard-MIDI-File-reader

I think this might end up being a web based application which I didn't expect.