'Declare some variables
dim RS, pid
Set RS = Server.CreateObject("ADODB.Recordset")
pid = Request.QueryString("pid")
sql = "SELECT * FROM mytable WHERE id= " & pid & " order by datum"
RS.Open sql, CS
'This is the the code which tells the page to open Excel and give it the data to display
Response.ContentType = "application/vnd.ms-excel"
'You can give the spreadsheet a name at the point its produced
Response.AddHeader "Content-Disposition", "attachment; filename="& pid&".xls"
loopCounter = 0
Note that I have formatted the output header here to a dark blue background and white text
this will be reflected in the spreadsheet when its produced and you could extend this to your own tastes of course.