I am trying to write a vbscript (GetExcelData.vbs) to extract data from an excel file. I have been able to have LiveCode write the .vbs file and execute it but only if I already have the file path and file name in the procedure to write the *.vbs file. What I would like to do is to have the user select the file in which the data resides, then process the file and finally pass back the information into a datagrid. Does anybody know how I can achieve this.
Here is my function. It will get the data if the file is already open. I want the user to select the file, then the VBScript extracts the data from the file that has been selected by the user, then shuts it all down and deletes the VBScript.
Function GetExcelData pRangeRef
put "Dim ObjXL,tNumRows,tNumCols,tRetVal,tRow,tCol" & cr & \
"Set ObjXL = GetObject(," & ("Excel.Application") & ")" & cr & \
"tNumRows = ObjXL.Range(" & (pRangeRef) & ").Rows.Count" & cr & \
"tNumCols = ObjXL.Range(" & (pRangeRef) & ").Columns.Count" into tScript
put tScript & cr & "For tRow = 1 To tNumRows" & cr & \
"For tCol = 1 to tNumCols" & cr & \
"If tCol <> tNumCols Then" & cr & \
"tRetVal = tRetVal & ObjXL.Range(" & (pRangeRef) & ").Cells(tRow,tCol).Value & vbTab" & cr & \
"Else" & cr & \
"tRetVal = tRetVal & ObjXL.Range(" & (pRangeRef) & ").Cells(tRow,tCol).Value & vbCrLf" & cr & \
"End If" & cr & "Next" & cr & "Next" into tScript
put tScript & cr & "tRetVal = Left(tRetVal,Len(tRetVal) - 2)" & cr & \
"WScript.Echo tRetVal" into tScript
put "C:\VBSTemp.vbs" into tFile
put tScript into url("file:" & tFile)
set the hideConsoleWindows to true
get shell("cscript.exe //nologo" && tFile)
send "delete file" && q(tFile) to me in 1 second
if char -1 of it is CR then delete char -1 of it -- strip any trailing CR
return it
break
end switch
end GetExcelData
Any Help would be much appreciated
Connect to Excel using VBscript
Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Return to “Getting Started with LiveCode - Complete Beginners”
Jump to
- LiveCode Community
- ↳ Announcements
- ↳ Developer Services Marketplace
- ↳ User Groups and Events
- ↳ SoCal LiveCode Group
- ↳ Greater Toronto Area LiveCode Users Group
- ↳ Off-Topic
- ↳ Made With LiveCode
- Getting Started With LiveCode
- ↳ Getting Started with LiveCode - Complete Beginners
- ↳ Getting Started with LiveCode - Experienced Developers
- ↳ Converting to LiveCode
- Developing With LiveCode
- ↳ Talking LiveCode
- ↳ Databases
- ↳ Games
- ↳ Internet
- ↳ Multimedia
- ↳ Software Engineering
- ↳ Version Control
- ↳ Feature Proposals
- ↳ Bug Triage
- Extending LiveCode
- ↳ Using Plugins for Customizing the LiveCode IDE
- ↳ Using Externals
- ↳ Making IDE Plugins
- ↳ Building Externals
- ↳ LiveCode Builder
- Platform Specific
- ↳ Windows
- ↳ Mac OS
- ↳ Linux
- ↳ iOS Deployment
- ↳ Android Deployment
- ↳ CGIs and the Server
- ↳ HTML5
- ↳ Raspberry Pi
- Academic Endeavors
- ↳ Teaching with LiveCode
- ↳ Research and Post Secondary
- ↳ LiveCode University
- ↳ Educational Outreach
- Livecode Open Source Archived Forum- closed to posting
- ↳ Engine Contributors
- ↳ IDE Contributors
- ↳ Documentation and Tutorials
- ↳ Brainstorms
- ↳ Community Projects
- LiveCode Hosting