Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <hta:application applicationname=excelhelper border=dialog innerborder=no
- maximizebutton=no scroll=no singleinstance=yes />
- <title></title>
- <style>
- html {
- background-color: buttonface;
- }
- label {
- display:inline-block;
- width: 12ex;
- }
- #inpSerialNumber {
- margin-top: .5em;
- }
- #btnProcess {
- margin-left: 12ex;
- }
- </style>
- <label for=inpProductCode>Product Code:</label>
- <input id=inpProductCode value=test required /><br />
- <label for=inpSerialNumber>Serial Number:</label>
- <input id=inpSerialNumber /><br />
- <br />
- <input type=button id=btnProcess value=Process disabled />
- <p id=msg>Retrieving Excel application instance...</p>
- <!-- ===== Script Initialization ===== -->
- <script language=vbscript>
- dim objExcel
- Const ForAppending = 8
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objShell = CreateObject("WScript.Shell")
- InputFile = "\\oldenzaal06\common\Ebike\EPACLabel\models.csv"
- LabelFile = "\\oldenzaal06\common\Ebike\EPACLabel\EPAClabel.btw"
- LogFile = "\\oldenzaal06\common\Ebike\EPACLabel\log\"
- OutputFile = objShell.ExpandEnvironmentStrings("%UserProfile%") & _
- "\Desktop\EPACLabel.txt"
- wid = 300
- hei = 200
- resizeto wid, hei
- moveto (screen.width-wid)/2, (screen.height-hei)/2
- appTitle = "Excel Helper"
- document.title = appTitle
- </script>
- <!-- ===== Task Initialization ===== -->
- <script for=window event=onload language=vbscript>
- On Error Resume Next
- set objExcel = nothing
- Set objExcel = CreateObject("Excel.Application")
- if objExcel is nothing then
- msgbox "Failed to retrieve Excel application instance." &vbcrlf& _
- err.description, vbCritical, appTitle
- close
- end if
- msg.innerText = "Opening Excel document..."
- set objWorkbook = nothing
- if ucase(right(InputFile, 4)) = ".CSV" then
- objExcel.Workbooks.OpenText(InputFile)
- else
- objExcel.Workbooks.Open(InputFile)
- end if
- if objExcel.ActiveWorkbook is nothing then
- msgbox "Failed to open Excel document." &vbcrlf& err.description, _
- vbCritical, appTitle
- close
- end if
- btnProcess.disabled = false
- msg.innerText = "Ready for processing."
- </script>
- <!-- ===== Processing ===== -->
- <script for=btnProcess event=onclick language=vbscript>
- On Error Resume Next
- ProductCode = trim(inpProductCode.value)
- If ProductCode <> "" Then
- SerialNumber = trim(inpSerialNumber.value)
- intRow = 2
- Do until objExcel.Cells(intRow, 1).Value2 = ""
- ProductRange = objExcel.Cells(intRow, 1).Value
- sType = objExcel.Cells(intRow, 2).Value2
- sColor = objExcel.Cells(intRow, 3).Value2
- '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
- oFile = empty
- Set oFile = nothing
- Set oFile = objFSO.CreateTextFile(OutputFile, true)
- if not (oFile is nothing) then
- oFile.WriteLine sType &","& sColor &","& SerialNumber &","& aYear
- oFile.Close
- e = objShell.Run("cmd /c ""%ProgramFiles(x86)%\Bartender\Bartend.exe"" /f=""" & _
- LabelFile & """ /p /d=""" & OutputFile & """", 0, true)
- if e = 0 then
- msgbox "Input has been processed.", vbInformation, appTitle
- else
- msgbox "Failed to execute application.", vbCritical, appTitle
- end if
- else
- msgbox "Failed to create " & OutputFile & " file." &vbcrlf& _
- err.description, vbCritical, appTitle
- end if
- exit do
- End If
- intRow = intRow + 1
- Loop
- if aYear = empty then
- msgbox "Product code is not found." &vbcrlf&vbcrlf& _
- "Note: Product code is case sensitive.", vbCritical, appTitle
- end if
- Else
- msgbox "Please enter a product code (case sensitive).", vbCritical, appTitle
- End If
- </script>
- <!-- ===== Clean up ===== -->
- <script for=window event=onbeforeunload language=vbscript>
- if not (objExcel is nothing) then objExcel.Quit
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement