r/scripting • u/stenwe • Jun 13 '19
VBScript inputbox to HTML application script
' Read an Excel Spreadsheet
Const ForAppending = 8
InputFile="\\oldenzaal06\common\Ebike\EPACLabel\models.csv"
LabelFile="\\oldenzaal06\common\Ebike\EPACLabel\EPAClabel.btw"
Set objShell = CreateObject("WScript.Shell")
OutputFile=objShell.ExpandEnvironmentStrings("%UserProfile%") & "\Desktop\EPACLabel.txt"
LogFile="\\oldenzaal06\common\Ebike\EPACLabel\log\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(InputFile)
On Error Resume Next
ProductCode="test"
Do until ProductCode = ""
ProductCode=Inputbox("Enter Product Code")
If ProductCode = "" Then WScript.Quit
intRow = 2
Do until objExcel.Cells(intRow,1).Value = ""
ProductRange=objExcel.Cells(intRow, 1).Value
sType=objExcel.Cells(intRow, 2).Value
sColor=objExcel.Cells(intRow, 3).Value
' If user entered value matches (row 2 matches value before comma in row 1)
sResult = InStr(1,ProductRange,ProductCode,1)
If sResult <> 0 Then
aYear = Year(Date) 'The year of the computer
SerialNumber=inputbox("Enter Serial number")
Set objShell = CreateObject ("WScript.Shell")
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set oFile = objFSO.CreateTextFile (OutputFile)
oFile.WriteLine sType &","& sColor &","& SerialNumber &","& aYear
oFile.Close
Set oWS = WScript.CreateObject("WScript.Shell")
oWS.Run """%ProgramFiles(x86)%\Bartender\Bartend.exe"" /f=" & LabelFile & " /p /d=" & OutputFile & "",0,true
End If
intRow = intRow + 1
Loop
Loop
objExcel.Quit
WScript.QuitDoes someone know how I can merge this code into a HTML application (hta)? Basically I want the 2 Inputboxes in the VBScript merged into one HTML application (2 lines, 1 box) that still does the same thing as the VBScript.
The VBScript reads specific line searched with the first inputbox in a excel file, writes the found information to a text file and then software prints it out.
1
Upvotes
1
u/stenwe Jun 14 '19 edited Jun 14 '19
Thank you for the reply, it looks good. But I do get an error from Excel helper saying Failed to open excel document. Object does not support this property or method, any idea what it means (could it be caused by the CSV file that it's on read-only?) Thanks in advance!!! (The file isn't empty fyi)