I followed Peter's answer here to create a VBA macro that pushes data to a Google Form by building a URL and sending it through an http object. I would like to accomplish this without having to open Excel, so I'm converting the VBA code to VBS and pulling data from a text document. I got the VBA version working, but I can't seem to get the VBS version to submit right, and need some help. I'm still a beginner at VBS.
When I use Peter's code as written, this block gives me an error: "ActiveX component can't create object: 'MSScriptControl.ScriptControl'
Set http = CreateObject("MSXML2.XMLHTTP")
Set ScriptEngine = CreateObject("MSScriptControl.ScriptControl")
ScriptEngine.Language = "JScript"
ScriptEngine.AddCode "function encode(str) {return encodeURIComponent(str);}"
When I remove all but the "Set http = CreateObject("MSXML2.XMLHTTP") line, the code runs fine, but the data ends up in the connected Google Sheet in a single cell with each entry separated by a comma, instead of each entry in a separate cell like normal. I think it has something to do with how the URL is formatted when it's sent from the VBScript as opposed to the VBA macro.
In order for the VBA macro to work, I had to check Microsoft XML.V3.0 in the VBA Reference menu, which I think enabled the ScriptEngine portion of the code to work, but I don't know what the equivalent of adding a reference is in VBS, or if it's even required.
Here is how I modified Peter's code for VBS:
Dim ScriptEngine
Dim http
Dim myURL
Dim strLine
Dim exportLine
Set http = CreateObject("MSXML2.ServerXMLHTTP")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDataFile = objFSO.OpenTextFile("data_file.csv", ForReading)
strLine = objDataFile.ReadLine
exportLine = Split(strLine,",")
myURL = "https://docs.google.com/forms/d/e/ . . . . /formResponse?" & _
"entry.xxxxxxxxx=" + exportLine(0) + _
"&entry.yyyyyyyyy=" + exportLine(1) + _
"&entry.zzzzzzzzz=" + exportLine(2).Text
http.Open "GET", myURL, False
http.setRequestHeader "User-Agent", "Google Chrome 70.03538.102 (compatible; MSIE _
6.0; Windows NT 5.0)"
http.send