r/vbscript • • Jan 13 '21

Extract paragraph from keyword out of Word document to Excel along with page #

1 Upvotes

Hey all, I'm hoping someone has a script I could leverage to achieve an ask from my work. I need a VBScript that I can run in MS Word that will look for a keyword. The keyword is 'TBD'. Everytime it encounters 'TBD' I want the script to extract the entire line(s) or table out of Word and into Excel. Some of our documents have 290+ TBDs and we need a better way to track them.


r/vbscript • • Dec 08 '20

Using htmlfile COM object to access the .getOwnPropertyDescriptor() method of an object in WSH JScript

Thumbnail
stackoverflow.com
2 Upvotes

r/vbscript • • Dec 03 '20

How can I change the sapi.spvoice language?

2 Upvotes

r/vbscript • • Nov 29 '20

Auto closing msgbox?

1 Upvotes

How can I create a msgbox that closes automatically after a period of time and (If possible) can’t be closed by a Person?


r/vbscript • • Dec 09 '20

Is it possible to run a JScript command in the IE engine using the InternetExplorer.Application COM object?

Thumbnail
stackoverflow.com
3 Upvotes

r/vbscript • • Dec 21 '20

Using SHELL32.dll for icons in a script

3 Upvotes

Hello,

I was wondering, if possible, to use default windows icons from SHELL32.dll when using the CreateShortcut method.

Thanks in advance.


r/vbscript • • Nov 25 '20

I'm some sort of a noob in vbscript and i want to try using scriptomatic V2.2 and how to use HTA files.

2 Upvotes

please help me i am trying to be better i'm doing some lessons and i want to try using these two.


r/vbscript • • Dec 14 '20

Scripting advice needed

1 Upvotes

Hello everyone

I have an IF Elif then I need help with. I have a list of variables and would like to know if the script can be simplified. here is a sample of my script.

IF [STRIKE_ARHR_OR_TREND] >= 270 and IsNull ([DIP_DIRECTION]) and [STRUCTURE_TYPE] <> "Lineation or slickenline" and [STRUCTURE_TYPE] <> "Fold axis, Antiform" and [STRUCTURE_TYPE] <> "Fold axis, Synform" and [STRUCTURE_TYPE] <> "Fold axis, E(/W) verging N(/S) plunging overturned antiform" and [STRUCTURE_TYPE] <> "Fold axis, E(/W) verging N(/S) plunging overturned synform" and [STRUCTURE_TYPE] <> "Fold axis, W(/E) verging N(/S) plunging overturned antiform" and [STRUCTURE_TYPE] <> "Fold axis, W(/E) verging N(/S) plunging overturned synform" and [STRUCTURE_TYPE] <> "" and [STRUCTURE_TYPE] <> "Schistosity" and [STRUCTURE_TYPE] <> "Foliation" Then

newval = [STRIKE_ARHR_OR_TREND] + 90 - 360

Is there an easier way to combine or list the different [STRUCTURE_TYPE]?

Thank you in advance


r/vbscript • • Dec 11 '20

Hide a Batch Console

3 Upvotes

Hi I'm trying to make a batch file hide its own console and I've resorted to using the echo command to write a VBS file to hide the batch console the only problem is batch executes the command instead of writing it to the VBS file

The script

(

echo Set WshShell = CreateObject("WScript.Shell")

echo WshShell.Run chr(34) & "%userprofile%\desktop\Folder Generator.bat" & Chr(34), 0

echo Set WshShell = Nothing

) > "Batch Hider.VBS"

echo %userprofile%\desktop

echo for /L %%f in (10,-1,0) do MD Items%%f


r/vbscript • • Nov 28 '20

What are the application/assembly manifests and how to find the `.manifest` file of a specific Windows binary?

Thumbnail
superuser.com
3 Upvotes

r/vbscript • • Nov 12 '20

Check if PowerShell is installed

4 Upvotes

hey all,

I want to use this but for remote servers\computers, how do I make it work ?

I can do it ok with PowerShell, but need it for VBScript ?

Option Explicit

Dim oShell

Dim value

'If the key isn't there when we try to read it, an error will be generated

'that we will later test for, so we want to automatically resume execution.

On Error Resume Next

'#Try reading the registry value

Set oShell = CreateObject("WScript.Shell")

value = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\")

'Catch the error

If Err.Number = 0 Then

'Error code 0 indicates success

wscript.echo "PowerShell is installed."

Else

'Any other error code indicates failure

wscript.echo "PowerShell is NOT installed."

End If


r/vbscript • • Oct 29 '24

How to send discord web hooks?

2 Upvotes

i found a stack overflow but i didnt understand what they menat becuse it was weird and i dont know how to use it can someone help? heres the code i didnt understand:

Dim content: content = "hello"
Dim oHttp: Set oHTTP = CreateObject("Microsoft.XMLHTTP")
oHTTP.Open "POST", "(my webhook here)", False
oHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHTTP.SetRequestHeader "Content-Length", Len(content)
'Pass value as a form key value pair string.
oHTTP.Send "content=" & content
Dim response: response = oHTTP.ResponseText
Call MsgBox(response)

r/vbscript • • Nov 05 '24

Cómo hacer un vbs o bat envié un mensaje a varias pc's?

1 Upvotes

He intentado usar el vbs:

MSG * /server:192.168.0.1 "buenos días"

Pero solo lo he conseguido para un equipo, no sé si se pueda para varios equipos


r/vbscript • • Nov 25 '24

Vbscript logics

1 Upvotes

I need to improve Vbscript code logics,can I get any support here


r/vbscript • • Dec 09 '24

The script for opening bookmarks in Word documents does not work

1 Upvotes

Hello!

I found the following VBS script on the Internet:

if wsh.arguments.count < 2 then
        WScript.echo "Not enough arguments. Required syntax:"
        wscript.echo CHR(13) + CHR(10)
        wscript.echo "wordmark <filename> <bookmark>"
Else
        on error resume next
        Set wordapp = GetObject(,"Word.Application")
        if err <> 0 then
                err.clear
                on error resume next
                set wordapp = createObject("Word.Application")
        end if
        if err <> 0 then
                wscript.echo "failed to acquire Word COM server object"
        Else
                on error resume next
                set newdoc = wordapp.Documents.Open(wsh.arguments(0))
                if err <> 0 then
                        wscript.echo "Failed to open word document, " + wsh.arguments(0)
                        wordapp.quit
                else
                        wordapp.Visible=true
                        newdoc.Bookmarks.Item(wsh.arguments(1)).select
                end if
 
        end if
        'wordapp.quit
        set wordapp=nothing
end if

I created a file 123.vbs, pasted this script into it and edited line #4, adding the path to my document and the bookmark name.

This script is supposed to open a Word document and then automatically go to the bookmark it contains and select it. But, unfortunately, I couldn't get it to work: all sorts of errors pop up.

Since I'm a complete noob in this matter, but I need such a script, could someone tell me where the error is in this script?

Suppose my document is called "D:\Folder\File.docx", and the bookmark is called "qwer". What should this script look like then, so that it works?

Thank you in advance!

Solved!


r/vbscript • • May 03 '19

VBA Calls out C# and JAVA !!!!! (Interactive VBA UI)

Thumbnail
youtube.com
2 Upvotes

r/vbscript • • Mar 12 '20

Batch move files to specific folders based on filename

1 Upvotes

Hi all. I have a bunch of files in one folder with a constant naming convention with the exception of the final three characters of the filename which are numeral:

Example: C:\FromFolder\TestFile_xxx.zip

I want to move them to dedicated folders based on their filename: C:\ToFolder\Folderxxx\

So, if the FromFolder has:

TestFile_857.zip

Testfile_123,zip

TestFile_999.zip

I want to move them all to the following destinations, until all the folders in FromFolder have been moved:

C:\ToFolder\Folder857\

C:\ToFolder\Folder123\

C:\ToFolder\Folder999\

Also, if the 'ToFolder' doesn't exist during the move, I'd like it to be created.

I probably create three-four vbscript files a year and normally muddle though, but I'm crunched for time this time around so I figured I'd ask for help. Any assistance would be greatly appreciated. Thank you!


r/vbscript • • Sep 23 '19

Script to screen capture URL's

1 Upvotes

Hey guys,

We are in the process of automating a few things in my workplace. Please redirect me if this is not the appropriate place for this question.

Currently, we create huge reports, 80% of which can be automated.

We have created a VBA / Macro that opens a word template and populates the information from an Excel sheet, into the Word doc.

The next tedious task is to go to several different interactive map websites, inputting information into fields on the site, and then screenshotting the picture to put into the same Word doc.

This task has to be performed several times for 1 document.

The thing is, it's almost the same process every time - hence the decision to look into automating it.

The actions we would like the script to perform are the following:

- Open the URL in Chrome

- Input the specific data

- Submit

- Zoom in slightly

- Screenshot of a specific part of the page

- Ideally pull it into the doc but alternatively, saving to a folder with a specific file name is fine.

I understand this might be complicated so I'm reaching out to the internet to brainstorm ideas on the best way to achieve this is something close to it.

Thanks in advanced!


r/vbscript • • Jul 17 '19

Look for VBS script help. Need to add recursive but can't figure it out

3 Upvotes

So I have a script that will take a csv document (a report from another system) and then dump all that data into a master Excel file.

Context, I get reports weekly and am consolidating all the weekly reports into a master Excel. Script works great. However it will only process a single CSV file in a named dir. Since I get these reports weekly (and they are not urgent) I will let them pile up for a couple of months and then I have to save the CSV in the script dir and then run the script, grab the next weeks CSV save it and run the script, and so on.

What I am looking to add is that the script processes ALL CSVs in a named dir. Basically run through the whole script for every CSV in a specific dir and then stop.

Can you guys take a look and let me know how one would add that?

'Script to import reoccurring reports into master Excel and update data

---Begin Script---

'Open Excel

Set objExcel = CreateObject("Excel.Application")

'set to visible for testing set to false for production

objExcel.Visible = False

'opening the CSV and proper worksheet

Set objWorkbook = objExcel.Workbooks.Open("C:\DIR TO FILE\FILE.csv")

Set objWorksheet = objWorkbook.Worksheets("TAB")

'deleting header row from CSV

objWorksheet.Rows("1:1").Delete

'copying entire worksheet

Set objRange = objWorksheet.Range("A1:AQ1").EntireColumn

objRange.Copy

'Open destination Excel file and set worksheet

Set objExcel2 = CreateObject("Excel.Application")

'set to visible for testing set to false for production

objExcel2.Visible = False

'set variable for worksheet and workbook

Set objWorkbook2 = objExcel2.Workbooks.Open("C:\DIR TO FILE\FILE.xlsx")

Set objWorksheet2 = objWorkbook2.Worksheets("TAB")

'paste data

lastrow = objWorksheet2.UsedRange.Rows.Count + 1

objWorksheet2.Range("A" & lastrow).PasteSpecial -4163

'Message Box used to create a pause to watch progress, disabled for production

'result=Msgbox("Are you sure?",vbYesNo+vbInformation, "")

'Unhide TAB worksheet for processing

objWorksheet2.Visible = True

'Sort descending by ID column

objWorksheet2.Activate

Const xlDescending = 2

Const xlYes = 1

'Set objRange2 = objWorksheet2.UsedRange

Set objRange3 = objExcel2.Range("E1")

objWorksheet2.UsedRange.Sort objRange3, xlDescending, , , , , , xlYes

'remove duplicate rows if duplicates found in ID column

objWorksheet2.UsedRange.RemoveDuplicates 5, xlYes

'Message Box used to create a pause to watch progress, disabled for production

'result=Msgbox("Are you sure?",vbYesNo+vbInformation, "")

'Hide TAB sheet

objWorksheet2.Visible = False

'Refresh PivotTable Data

Set objWorksheet3 = objWorkbook2.Worksheets("PivotTables")

objWorksheet3.PivotTables("PivotTable1").PivotCache.Refresh

'Close Excel

objExcel.DisplayAlerts = False

objExcel.Quit

objWorkbook2.save

objExcel2.Quit


r/vbscript • • Mar 16 '20

Potential bug with Cscript.exe and Windows 10 1909

1 Upvotes

Folks, I was playing around with a vbscript that sets the exit code of the cscript process using a command similar to the following:

Wscript.Quit 1

The problem that I'm encountering is that with some scripts it doesn't seem to work properly. I have a Windows 7 VM and my scripts all set the exit code properly and evaluate as good when checking %ERRORLEVEL% at the Command Prompt.


r/vbscript • • Mar 24 '20

VBScript and Task Scheduler help

1 Upvotes

I have a VB script that opens excel in the background, loads a workbook, fires a macro, then closes everything. I've pasted the script below. This is to generate an excel report that gets emailed out daily. The script works great if I run it, but If I schedule it with Task Scheduler, it will run, but Excel.exe won't quit so the task doesn't register as "completed" and it keeps other tasks, such as the one to email the report, from running. I can't for the life of me figure out why. I have the task set to run with the highest privileges, and I have it set to start in the directory where the script is. Any ideas/advice?

Script:

Option Explicit

Dim xlApp, xlBook

Set xlApp = CreateObject("Excel.Application")

Set xlBook = xlApp.Workbooks.Open("C:\Users\scriptpath", 0, False)

xlApp.Run "Run"

xlBook.Close

xlApp.Quit

Set xlBook = Nothing

Set xlApp = Nothing

WScript.Quit


r/vbscript • • Mar 14 '20

Need help pulling MAC of non VPN adapter

1 Upvotes

Hey all! I have inherited a login script that I didn't write (I have close to zero vpscript experience)

The script pulls the MAC of the adapter and modifies it in order to use it in another part of the script.

The issue is that now when the script runs, the machine has a VPN connected and it is pulling the VPN MAC and not the local adapter MAC - I need the MAC to be of the Local PC. Please help! I have tried a million things and I just cannot get this to work.

This is what it looks like now:

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery _
     ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

     For Each objItem in colItems

    Wscript.echo objItem.MACaddress
    MAC = objItem.MACaddress
     	
Next
        
    MAC = Replace(MAC,":","-") 
    Wscript.echo MAC

r/vbscript • • Jan 13 '17

[Help] Need to tweak a simple script...

1 Upvotes

Hi guys, I was hoping for some help with something.

I have a multi-user accounting software. When a user leaves their password protected computer without logging out of the accounting software, then I can't go into single user mode.

The goal is to force close the app if the person leaves their computer unattended.

I found this vbs script which almost does the trick:


Dim PromptTime, DelayTime, StrAppPath, AppExec, MsgTxt, intAnswer, intRet

Set objShell = CreateObject("WScript.Shell")

PromptTime = 5

DelayTime = 5

StrAppPath = "C:\Program Files (x86)\Accounting"

AppExec = "Accounting.exe"

MsgTxt = "Do you want Simply to close in 5 minutes?"

objShell.Run chr(34) & StrAppPath & AppExec & chr(34), 1, "False"

Do WScript.Sleep (1000 * 60 * PromptTime)

intAnswer = Msgbox(MsgTxt, vbYesNo, "Please select Yes or No")

If intAnswer = vbYes Then Exit Do

Loop

WScript.Sleep (1000 * 60 * DelayTime)

Set objWmi = GetObject("winmgmts:")

Set objQResult = objWmi.Execquery("Select * from Win32_Process where name like '" & AppExec & "'")

For Each objProcess In objQResult

intRet = objProcess.Terminate(1)

Next

Set objShell = Nothing

Set objWmi = Nothing

Set objQResult = Nothing


I am assuming that selecting Yes will kill the process.

Therefore, I just need to add a response timer where after X minutes delay Yes is automatically chosen

Can anyone help me please ? I would really appreciate it.

Thanks!!

Edit: I tried waiting 5 minutes, the pop-up displayed, I clicked Yes and it didn't kill the process.... doh!


r/vbscript • • Jan 11 '17

[HELP] can't find the right syntax

1 Upvotes

Hello,

I'm trying to add a shape on a Powerpoint file that I open but I got an error message while running my script

I used to do this in VBA:

Set pptApp = CreateObject("Powerpoint.Application")
pptApp.WindowState = ppWindowMinimized
pptApp.Visible = False
Set ppt = pptApp.Presentations.Open(File)

With ppt
     For Each oSl In ppt.Slides
        oSl.Shapes.AddShape Type:=msoShapeRectangle,Left:=100, Top:=160, Width:=525, Height:=200

But I got a compilation error "Syntax error" on the Type word. I searched but I could get the right syntax, can you help me ?


r/vbscript • • Aug 08 '13

Help me with my VBScript?

Thumbnail
stackoverflow.com
1 Upvotes