There is some example code here

http://www.excel-it.com/vba_examples.htm