'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Create an Excel file on the desktop with the first 10 cells filled and ask to open it'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
dim Excel, WB, WS, Cell, i, Shell, Folder, FilePath, FolderItem 
  
Shell = CreateObject("Shell.Application")
try
  Folder = Shell.Namespace(0)   
  FilePath = Folder.Self.Path + "\TwistpadExcelSample.xlsx" 
finally
  Folder = Unassigned 
  Shell = Unassigned 
end try
    
Excel = CreateObject("Excel.Application") 
try
  WB = Excel.Workbooks.Add
  WS = WB.Worksheets(1)

  for i = 1 to 10 
    Cell = WS.Cells(i, 1)
    Cell.Value = "Cell " + IntToStr(i) 
    Cell = Unassigned 
  next
    
  WB.SaveAs(FilePath)

  WB.Close(False)
  WB = Unassigned
  WS = Unassigned
finally
  Excel.Quit 
  Excel = Unassigned 
end try

if MsgBox("Open the created Excel file?", vbYesNo, "Twistpad") = vbYes then
  Shell = CreateObject("Shell.Application") 
  Folder = Shell.Namespace(0)
  FolderItem = Folder.ParseName(ExtractFileName(FilePath)) 
  FolderItem.InvokeVerb("Open")
  FolderItem = Unassigned 
  Folder = Unassigned 
  Shell = Unassigned 
end if
