Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Cannot find object

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,46694
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Cannot find object
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Cannot find object - 5/6/2007 11:22:24 PM   
  JimmyFo

 

Posts: 5
Score: 0
Joined: 9/20/2005
Status: offline
Hi folks, I have a grid view on a content page and on the content page are a number of things: an ASP.net gridview control, a button with the function name "Export()" in the "onclientclick" property, and this function which I'm trying to use to export to excel:

 
<
script type="text/vbscript">

Function Export()
msgbox(
"In Func")
On Error Resume Next
Dim sHTML, oExcel, fso, filePath
Dim oelem
'oelem = document.body.childNodes("grid")
'oelem = document.all("grid")
oelem = document.getElementById(
"grid")
If oelem Is Nothing Then 'you cannot find it
msgbox(
"cannot find grid")
Exit Function 'early exit, you can wrap the whole functional part in the else if part if you like
End If
Dim slen
slen = oelem.length 'make sure it is not dispHTMLElementCollection
If err.number = 0 Then
msgbox(
"error number <> 0")
Exit Function 'there are more than one element of "grid" return, you have to reconsider how to deal with it
End If
err.clear
sHTML = document.all(
"grid").outerHTML
msgbox(sHTML)
fso = CreateObject(
"Scripting.FileSystemObject")
filePath = fso.GetSpecialFolder(2) &
"\MyExportedExcel.xls"

'fso.CreateTextFile(filePath).Write(sHTML)
fso.CreateTextFile(filePath)
wscript.sleep(1000)
oExcel.Workbooks.open(filePath)
Dim i
'SET i = 0
i = 0
Do While Not fso.fileexists(filePath)
'err.Clear() 'no need
filePath = fso.GetSpecialFolder(2) &
"\MyExportedExcel" & i & ".xls"

'why do you write something like this to an xls file??? disregarding exist or not???
'fso.CreateTextFile(filePath).Write(sHTML)
i = i + 1
Loop


oExcel = CreateObject(
"Excel.Application")
'IF err.number>0 OR oExcel =NULL THEN
If err.number <> 0 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.Workbooks(1).WorkSheets.cells(1, 1) = sHTML
oExcel.Visible = True
fso = Nothing
End Function

</
script>


The two message boxes that pop up on click are "in Func" and "cannot find grid" - meaning it can't find the gridview, I assume. No other errors appear.

1) This is a content page, but I don't see how that could affect it.
2) This has an ASP.Net AJAX script manager on it, but even on pages without it, I still can't get it to work.

Any ideas?
Thanks!
James
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Cannot find object Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts