Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been working on a solution for weeks for a 9 year old applicaiton. I need to export a DataGrid to Excel. The Response method will not export large datasets so I want to use ActiveX.

I currently have a button ibtnExcel_Click and want to export "grdResult" content - this is the DataGrid. I also want to remove a Checkbox control.

Shown below is my VBScript code. I need help to modify it.

Sub ibtnExcel_Click()

ON ERROR RESUME NEXT
DIM sHTML, oExcel, fso, filePath

sHTML = document.all(grdResult).outerHTML

SET fso = CreateObject("Scripting.FileSystemObject")
filePath = fso.GetSpecialFolder(2) & "\MyExportedExcel.xls"
fso.CreateTextFile(filePath).Write(sHTML)

DIM i
SET i = 0

DO WHILE err.number > 0
err.Clear()
filePath = fso.GetSpecialFolder(2) & "\MyExportedExcel" & i & ".xls"

i = i + 1
LOOP

SET oExcel = CreateObject("Excel.Application")
IF err.number>0 OR oExcel =NULL THEN
msgbox("You need to have Excel Installed and Active-X Components Enabled on your System.")
EXIT FUNCTION
END IF

oExcel.Workbooks.open(filePath)
oExcel.Workbooks(1).WorkSheets(1).Name = "My Excel Data"
oExcel.Visible = true
Set fso = Nothing
Posted
Updated 3-Feb-10 10:47am
v2

Have you considered taking the contents of your datagrid and exporting it to a more generic format such as .csv (comma separated values)? ie: Basically creating a text file that can be opened in Excel (or any other program capable of opening text files).

This will get around a whole host of issues.
 
Share this answer
 
Do you have resources that could point me to regarding exporting to csv?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900