VB Script





VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hello, All.

working on the last part of this project.
At least for the math anyway.

I have all my time in the database set as minutes.
90 = 1:30:00
So, what I need to do now, is convert the minutes into seconds.
90 = 5400

Everything I am finding is for the reverse.
Seconds into Minutes or hours.
Nothing for the opposite.

Any idea's on this one?
Hello, All.

I need to subtract time.
My output is the following format.

Time of Video = 01:30:00
Time played    = 00:07:17

I tried the accepted code from this post here. VBScript Time difference

I THINK I am using it correctly.
So, I tried the following.

theMTS = "00:07:17"
TTime = "01:30:00"


Open in new window

Output SHOULD be: 01:22:43

I get the following error.

Microsoft VBScript runtime error '800a000d'
Type mismatch: 'Cint'
/media/test2.asp, line 96

This is the line 96
BegTime = Cint(iStart)

Here is the code from the above-mentioned page.

Function SubtractTimes(iStart, iEnd)
' Given the following input values...
'    @TimBeg = 0815
'    @TimEnd = 1000
' the result should be 0145

Dim BegTime  ' Beginning time converted to an integer
Dim EndTime  ' Ending    time converted to an integer
Dim BH       ' Beginning hour converted to minutes since midnight
Dim BM       ' Beginning mins
Dim BT       ' Beginning time in minutes since midnight
Dim EH       ' Ending hour converted to minutes since midnight
Dim EM       ' Ending mins
Dim ET       ' Ending time in minutes since midnight
Dim TM       ' Total minutes in interval
Dim IH       ' Interval hours
Dim IM       ' Interval mins
Dim IT       ' 

Open in new window

I have an Excel spreadsheet populated with data only in column A. The number of rows vary.
Each cell in column A (A1, A2, ...) is filled with a text that starts with a number appended with a text string.
Eg: A1 = "102heaven"; A2 = "56flower"....
I need a macro that will put the number in column B and the text in column C
A1="102heaven" --> B1 = 102 and C1 = "heaven"
Hey Everyone,

I'm looking to create an Access 365 sub that does the following things:

1.)  Creates a Folder
2.)  Exports the results of a query to that folder in a .txt tab delimited format
3.)  Copies a file from the C drive to this folder
4.)  Zips the folder

I'm a novice with coding in general so I'm being stopped at step 2.  My code to create the folder is:

Dim rstemp As String
rstemp = "//SharedDrivePath/" & Me.OrderID.Value & ".FlowerOrder"
If Dir(rstemp, vbDirectory) = "" Then MkDir rstemp

Open in new window

That seems to work well

The query I want to export is based on a single table.  So getting the query to work is easy, but exporting as a .txt file has tripped me up.  Everything I try fails.

Here is an example table:
I've also attached that example table here as an excel sheet.

This is my basic select query with some slight formatting:

SELECT [FlowerName] & "_" & [Color] AS Flower_Color, Format([SproutDate],"yyyy/mm/dd") & "_" & Format([SproutDate],"hhnn") AS FormatSproutDate, FlowersTable.ScanCode, FlowersTable.FrostDate
FROM FlowersTable;

Open in new window

The resulting query looks like this:
If anyone could help me with this I would really appreciate it.  Thank you and have a wonderful day.
NOTE : This is a follow up question from : https://www.experts-exchange.com/questions/29139469/Macro-to-convert-data-in-txt-into-excel-format.html?headerLink=workspace_answered_questions

Instead of having 1 set of data, i have multiple sets basically the structure is repeated several times.

Currently i am pasting the text file individually by transferring the multiples into 1 .txt file each so that the macro can read all the txt files and convert them to data in excel.
How to have a macro to also read text files with several repeated structure ?

See attached file. In this file, you can see that the structure appear 3 times.
Excel: Create new Sheet, parse heading into column against content of that column.

Example excel worksheet contains Sheet 1 with Columns A B C as address columns and intermittent rows containing contents under different headings in about 50 more columns.
Copy content to Sheet2 as per: For each column from Column D to Column BB, where a row contains content, copy the address row for Columns A B and C, plus the content from the row for the column, and add the column heading into the adjacent cell on the same row as per the example in Sheet 2.

PowerShell drag and drop, then hash the file that was dropped onto the form.
I can't figure out where to add something like "$fileHash = Get-FileHash -path $file -A SHA256" and then append to the file path.
The code below shows the file path when dragging a file, I want to hash that same file and add it's hash to the end
c:\some\file\path\here.txt, F70363B8AE41B113AC96F9762DB46262B8F436B29A4B7D1E2A3ADAB101E75299
I may further call a VirusTotal API call to look the hash up and append more info on the end later.
Right now all I need is the hash of the file(s) that get drug onto the form.

$Form1 = New-Object System.Windows.Forms.Form
$Form1.ClientSize = "391, 190"
$Form1.TopMost = $true
$TextBox1 = New-Object System.Windows.Forms.TextBox
$TextBox1.Anchor = "Top,Bottom,Left,Right"
$TextBox1.Location = "12, 12"
$TextBox1.Multiline = $true
$TextBox1.ScrollBars = "Both"
$TextBox1.Size = "368, 166"
$TextBox1.AllowDrop = $true
function FNprocess( $object ){
  foreach ($file in $object.Data.GetFileDropList()){

Open in new window

Hello experts,

I have the following procedure:
' File I/O constants
Const ForAppending = 8

'Create the file system object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Define folders and files to work with
strScriptDir = objFSO.GetParentFolderName(objFSO.GetFile(Wscript.ScriptFullName))
strLogFile = strScriptDir & "\log-copy.txt"
strStamp = TimeStamp(Now)
arrFolders = Array(ScriptDir)
strFromFolder = ""          ' Do not add trailing "\" to this variable
strToFolder = strScriptDir  "\Backups" ' Do not add trailing "\" to this variable
blnFolders = True
arrSkipFolders = Array("")

' Open log file for appending
Set objLog = objFSO.OpenTextFile(strLogFile, ForAppending, True)

' If the csv backup folder does not exist create it
strToPath = strToFolder
If Not objFSO.FolderExists(strToPath) Then
   objLog.WriteLine Now & " INFO: Created folder """ & strToPath & """."
End If

' Create a folder for todays backups
strToPath = strToPath & "\" & strStamp
If Not objFSO.FolderExists(strToPath) Then
   objLog.WriteLine Now & " INFO: Created folder """ & strToPath & """."
End If

' Loop through all folders, backup files
For Each strFolder in arrFolders
   BackupFilesFolders strFolder, blnFolders

' Wrap up

Wscript.Echo Now & " :" & vbCrLf & "Program has completed all the actions successfully"

' Process folder
Sub BackupFilesFolders(strPath, blnFolders)

   ' If the input 

Open in new window

Greeting Experts

I need to create a script to get a list of users in the Local Administrators Group on remote work stations. The script just needs to remote into each workstation using a text file with a list of device names and gather the names & Groups who are in the local Administrators Group in each pc.... Can somebody help me with this issue...
Excel ID rows in Column A are intermittently repeated.  The request is for a script to sum the repeated values in Column B and copy ID and total to Column D and E as per manual example in attached file.

Greetings Experts!

Working with vbscript and a limited (but growing, thanks to help received here!) knowledge of XML files, I'm trying to create a function that totals the quantities of materials issued to jobs by lot, bin, and serial number.  My XML file contains both material allocations (i.e. materials needed but not yet used) and material postings (i.e. specific information about materials that have been used).

In words, here’s what I’m trying to do:

For each material allocation, check to see whether the allocation has been completed. If it has not been completed, extract some information about the allocation from the XML and store it in a variable.  If it has been completed, look in the material postings and total up the quantities posted by lot, bin location, and serial number then store only those postings where the total quantity is not zero in the variable.

My latest attempt at this involved loading the material postings elements into an array and looping through that looking for lots that match the current lot and adding up the quantities. It kinda works but this will certainly take too long when my BOM has 500 items on it instead of 5 items.  Code shown here for context.

' create array of material postings
Dim arrMaterialPostings
arrMaterialPostings = BuildMaterialPostings(StockCodeSelection.CodeObject.Job)

Dim objDom, objAllocationsList, Counter, MyXML, objSerialNode, objBinNode, strBin, strSerial, EmptyXML
Dim objNodeList2, Counter2, 

Open in new window

I want to copy the application installation file or a vbs script on a share created on a file server.

on my workstation I want to have a text file with computer names in txt or csv format.

want to use a tool like psexec that executes a command on the remote computer

run the application or the vbs file on all the computers listed in the text file.

clients are windows 7 sp1

appreciate help
Hi Experts,

I have a report exported to Excel that contains info with headers and details.

looking to write a script that will just obtain all details along with the name portion of the header.

Purpose of this, to export all this into a SQL table.

See example attached.
Dear Experts,

I have the target to open all the existing .xls so Excel files in a certain folder through VB Script.

Actually found the following code which looks promising straightly providing that:

Set objFolder = objFSO.GetFolder("D:\Test")
For Each objFile in objFolder.Files
   If LCase(Right(objFile.Path, 4)) = ".xls" Then
      'do something
   End If

Open in new window

although pasting that code to a file with .vbs extension and double clicking on it, it brings VBScript runtime error:

Object required: 'objFSO'

Could you please advise how to fix that, eventually having some other code which could provide the same target?

Thanks in advance,
I need to run maco in Excel using command line or VBS. Please find attached the excel file with the maco and the vbs I created but it was not working.



'Create an instance of Excel
Set xlsApp = CreateObject("Excel.Application")
'Remove the following line to open Excel in the background
xlsApp.Visible = true
'Open your file
Set xlsWB = xlsApp.Workbooks.Open("D:\0 Aramco\0 Prpjects\0 UR\NA\System-A-B1-new-format_test_v3.xlsm")
'You can call macros connected to sheets or the workbook
Set xlsSheet = xlsWB.Worksheets(1)

'Call xlsWB.MakeFinal() 'To call a macro in ThisWorkbook
'Call xlsSheet.macroname() 'To call a macro in Sheet1

'False here just makes it not prompt to save

Open in new window

VBA Syntax

I have this line: Format(Date, "YYWW") but in January (e.g. 31/01/2019) this returns '195' week 5 is a single digit.

For single number weeks I need it to be in 2 digits so wee 5 would be '05'

Anyone know how?
Dealing with Locked Tables during debugging

I am tracking down an obscure bug which MAY be in the VB code or MAY be in any number of stored procedures and PROBABLYinvolves the delicate inter-dependency each has on the other.

So, while I am stepping through the VB code, I query the database and see the values before and after each step. But, just when I REALLY need to run the query, the table is locked (by the executing code). After the table is closed and the transactions are committed, only then can I run the query, but by then, it's too late. The error reveals itself and I had no way to see what was on the  database.


It would be awesome if I could set up a mirrored database that I could query to my heart's content. Is that an extreme idea?

I think I am going to need just such an extreme idea to do this...

Does SQL Server 2017 provide me anything I could do here? Ae there any kind of log files where these transactions can be viewed, even when the table is locked?

Maybe Visual Studio is the problem and I could benefit from getting a log of all data tables changes without even stepping through the code. Is there an SSIS feature or SQL Server feature that could output all DB changes for each table into a text file, for example? Then, I could scan it and see when the error showed up in the data.


I'm looking for a macro that will find the last row of data and then drag a formula from a specific cell down to that last row.  In the attached example, the formula is in C2.  I'd like the macro to identify row 6 as the last row containing data and then drag the formula from C2:C6.  The end result would show cells C3 and C4 as 'IV'.


What I'm trying to do
I'm trying to add to an existing VB Script (not VBA)  running locally, the ability to find and 'click' a hyperlink on a webpage.

One reference to such a script is:


In the answer, Erick states:

'To do this you need to add references to
"Microsoft Internet Controls"
"Microsoft HTML Object Library"'

I know how to do this in a VBA Project but can't find where to add such a library reference to a VB Script?

Is there a way to add this reference so it is available to all of my native VB Scripts (ie vb scripts I run from my own pc)  without having to create the reference to those libraries in each VB Script I develop?

And the opposite … what do I need to add to a local VB Script (assuming it was able to reference such libraries through my local global settings) if I wanted to send the script to another user who didn't have those library references installed on their system?

Available Tools
I normally develop my VB Scripts using notepad++.  I've just now downloaded Visual Studio 2019 RC (free edition) thinking I might be able to use it to add a reference library to this VB script but can't find how/where that would be done in VS (I'm a total novice with VS so it may be staring at me and I'm not recognizing it).
Hi Experts,

I have a function that does as follows.

Opens a given CSV file, reads in a loop each line of the file and uploads data to a web site.

I have an error procedure that whenever it returns in error (usually from that web site) it keeps a log of that error and moves on to process the next line.

Error procedure below.
    Close #1
    Set db = Nothing

    Exit Function
    s = "Insert into API_Errors(ErrorMessage,TableName, [TableID],FileName, ValuesSent) Values ('" & Err.Number & "--" & Err.Description & "','" & sTable & "'," & Nz(pk, "") & ",'" & sFile & "','') "
    CurrentDb.Execute s
    Select Case Err.Number
        Case 9
            '' display a message if you want
           Resume Next  '''' assuming you want to just pick up at the statement after the error
        Case Else
'            MsgBox Err.Number & "--" & Err.Description, vbOKOnly
'            Resume ExitImportDataToCaspio
            Resume Next
    End Select
End Function

Open in new window

Now would like to modify that as follows.

Have a table store some errors, in case this error is one of those, it should (instead of processing the next line) try one more time to process the current line.

For detailed description of the function see this..

Can someone help me I'm using a Zenworks command called zac ref from a commandline Zenworks allows you to run a remote script I just don't know how to incorparate the zac ref here is simple vb script
strComputer = "webserver"
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
Error = objWMIService.Create("notepad.exe", null, null, intProcessID)
If Error = 0 Then
    Wscript.Echo "Notepad was started with a process ID of " _
         & intProcessID & "."
    Wscript.Echo "Notepad could not be started due to error " & _
        Error & "."
End If

Open in new window


I am looking for a script that will tell me which AD  users have changed there passwords in the last 24 hours.

Was wondering if anyone had something similar.
Want to create an Excel macro that will take someone to the desired sheet by using the contents copied into the clipboard, but I have two problems:
1. When I run the macro below, I get a "Compile Error:  User-defined type not defined" on the first line.  The help reference didn't help (https://docs.microsoft.com/en-us/office/vba/Language/How-to/user-defined-type-not-defined).
2. When I tried to save the macro, it said that in order to save it with a VB Project, I needed to "choose a macro-enabled file type in the File Type list, but I couldn't find the File Type list under any of the menus and couldn't find it in Excel Help.  Thanks.

Dim DataObj As New MSForms.DataObject
Dim myString
myString = DataObj.GetText
Hi Experts,

This is in reference to the following.
I would like to have the lunch column getting populated with the correct amount.

Thanks in advance.
I have this macro that I believe compares the data in file called "compare" with data in another folder of my choice of which I put the name in  the file called compare.

Its then meant to look within the folder for the file name and compare that with what I have in the file called "compare"

I tried running it and it says that that it cannot find the file that im comparing  because its on the desktop of my PC.   I don't have any files on the desktop.

All files are in a folder called compare of which has the compare macro file and all other files that it has to look in.

Any ideas?

Private Sub CommandButton1_Click()
Dim WBs As Workbook, WBc As Workbook, cpath As String
Dim WSs As Worksheet, WSc As Object
Dim i As Long, j As Long, k As Integer, C As Boolean, R As Integer
Set WBs = Application.ActiveWorkbook
cpath = Application.ThisWorkbook.Path
Set WSs = WBs.ActiveSheet
Set WBc = Workbooks.Open(cpath & "\" & WSs.Cells(3, 8))
Set WSc = WBc.Sheets(WSs.Cells(3, 9).Value)
i = 4

C = False
Do While WSs.Cells(i, 1) <> ""
    j = 2
    C = False
    Do While WSc.Cells(j, 1) <> "" And C = False
        R = 0
        k = 1
        Do While WSs.Cells(i, k).Value = WSc.Cells(j, k).Value And k < 5
            k = k + 1
        If k = 5 Then
            C = True
            Exit Do
        End If
        j = j + 1
    If C = False Then
        WSs.Range("A" & i, "D" & i).Interior.ColorIndex = 6
        WSs.Cells(i, 5) =

Open in new window


VB Script





VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.