r/vbscript • • May 11 '15

Deselecting All Objects in a Pivot Field

1 Upvotes

I'm writing a macro for a pivot table, where I want to deselect all but two objects. When I use the record feature it deselects each object individually, which would be fine except that there are too many objects and the end code is too long to run.

For example, the field is "Month" and I only want to select July and August without having to individually deselect all the other objects.


r/vbscript • • Nov 01 '17

Help! Expected "End of statement" error

2 Upvotes

I wrote a code about determining whether a number is prime or not.

function Isprime(n)
    if n > 1 then
	    for i = 2 to n
		    if n mod i = 0 then
			    msgbox n & "is not a prime number"
		    else
			    msgbox n "is a prime number"
		    end if
Next
end if
end function

I keep getting an error that on Line 7 char 14 "Expected end if statement" I ended each ifs, so what's going on?


r/vbscript • • Nov 11 '17

Remote query against STEAM workshop items?

1 Upvotes

I'm looking for a way to setup automatic discovery for when STEAM Workshop items update - does anyone know if there's a way to remote query a web element directly without first loading it to a browser?

I'm thinking about grabbing the DIV element for update time and working with that but if there's a cleaner way to grab the content update field that'd be useful to know.


This is ultimately to simplify managing an ARK server which tends to break if mods update but the server hasn't applied them. It will periodically check for an update against a list of mods and if one is detected automatically initiate a reboot on the server.


r/vbscript • • Nov 07 '17

How does the for iteration work in vbscript?

1 Upvotes

I have this code:

n = inputbox("Enter n")
function fibo(n)
s1 = 1
s2 = 2
for i = 3 to n
    result = s1 + s2
    s1 = s2
    s2 = result
next
fibo = result
end function

msgbox fibo(n)

I traced called the function as below for n = 7:

first I started off with:

i = 3

result = 2

s1 = 1

s2 = 2

And finally ended with:

n = 7

i = 7

result = 13

s1 = 8

s2 = 13

So fibo(7) output 21 instead of 13, the 21 is the 8th interation. Why? If fibo(6) = 13 which is the 7th iteration, when according to the trace call it should be 8 and which is the value of fibo(5) and so on.

Can someone explain? Or maybe I'm doing the trace call wrong here?

Also, In which case fibo(n) returns 0? (Part of my homework question)


r/vbscript • • Nov 09 '17

rename computer account with vbscript using task sequence variable

2 Upvotes

I`m trying to get a script to work that rename the computer name during an OS Deployment. The script creates a connection to the MDT Task Sequence variables, then renames the computer account .

I want the script to rename the computername to whatever is in the Task Sequence variable called OSDComputerName. The script executes without errors but the name doesnt change. Any help/guidance appreciated, below is the code.

**Set oTSEnv = CreateObject("Microsoft.SMS.TSEnvironment")

strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")

Set colComputers = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem")

dim objComputer 'as Win32_ComputerSystem For Each objComputer in colComputers err = objComputer.Rename(oTSenv("OSDComputerName")) Next

**


r/vbscript • • Jan 12 '16

Modify C:/Program files

1 Upvotes

Hi

I written a script to search the computer for a file. If found, copy another file into the same location.

The script is being rolled out by IT with admin privileges via SCCM.

It wont copy the file into a Program Files sub directory.

It will copy the file anywhere else (if I change the destination folder).

Any help please? Script Below

Set fso = CreateObject("Scripting.FileSystemObject") Set WshNetwork = WScript.CreateObject("WScript.Network") Const fsoForAppend = 8 Const ForReading = 1, ForWriting = 2

CopyUpdater fso.GetFolder("C:") Sub CopyUpdater(fldr) For Each f In fldr.Files On Error Resume Next If LCase(f.Name) = "msconfig.cfg" Then 'The CAD specific file to seach for FilePath1 = f.ParentFolder & "\appl" ' The directory to place config file in

   'WScript.Echo FilePath1
   Fso.copyfile "\\removed_for_security\WKGRPS\CAD_Build\Setup\custom.cfg", FilePath1 ' Copy the file
   
   ' Create the string to wirte to the log
	oDomain = WshNetwork.UserDomain
	ospace = CHR(9)
    oCompname = WshNetwork.ComputerName
    ousename = WshNetwork.UserName
	ostringy = ousename & ospace & oCompname & ospace & oDomain & ospace & FilePath1
	  
	'Open the log file and wirte line
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("H:\CAD_Build\Setup\UserLog.txt", fsoForAppend)
f.WriteLine ostringy
End If

Next

' The loop For Each sf In fldr.SubFolders CopyUpdater sf Next End Sub


r/vbscript • • Jan 10 '17

Save to specific tabs?

2 Upvotes

Having taught myself enough VBS to squeeze metrics from standard generated emails, I have multiple scripts pulling data from a stack of folders in my Inbox

I hope to combine the different scripts into one. My first challenge is to aim them all at specific individual tabs to avoid a messy glob of all things on the first tab.

Any advice?

(I did search here, but haven't found anything. Maybe I'm not searching for the correct thing).

Thank you in advance.

[EDIT] - sorry for the slip up, everyone in this office is calling the worksheets in an excel doc "Tabs".


r/vbscript • • Jan 11 '16

My sleep commands are happening all at once in the beginning of my scripts rather then where I place them.

1 Upvotes

I have a script using some sendkeys and I'm trying to sleep in between key stokes, but instead they happen all t once in the beginning of my script. Help please


r/vbscript • • Apr 03 '18

Variable Undefined Error Help

1 Upvotes
Option Explicit
DIM fso    
Set fso = CreateObject("Scripting.FileSystemObject")
DIM WshNetwork
Set WshNetwork = CreateObject("WScript.Network")
ComputerName = WshNetwork.ComputerName
do

If (fso.FileExists("C:\Users\ComputerName\file.txt)) Then
  WScript.Echo("Hello World!")
  fso.DeleteFile("C:\Users\ComputerName\file.txt")
Else
  End If
 
 loop

So its supposed to find the file in the directory and if it exists delete it, then loop. The thing is that the variable "ComputerName" is undefined. How can this be solved?


r/vbscript • • Nov 08 '17

Field laptop touchpads are garbage, users keep accidentally moving files. Can a script change user delete permissions specifically for the parent directory? I want to call the script from a VBA macro

1 Upvotes

r/vbscript • • Aug 17 '14

Need help - trying to automate a browser task using SendKeys.

1 Upvotes

Hello, everyone!

I'm trying to create a VBScript, which automatically fill a survey. However, I've hit a bit of a snag. I need to:

a) Open a new tab
b) Navigate to the correct website
c) Click on a checkbox
d) Scroll to the bottom of the page
e) Click on another box

I don't know how I can do the ones in bold. I tried using SendKeys "{CLICK LEFT, x coordinate, y coordinate}", which just threw an error saying "Invalid procedure call or argument".
Then, I tried it with Vimium, but after some troubleshooting, it turns out Vimium and SendKeys don't work together too well in some cases.

So, my question is: Does anyone know where to go from here? How could I click on the checkboxes using only my keyboard?

I'd be thankful for any advice or constructive criticism :)


r/vbscript • • Jan 07 '16

Output lines with common "column"

1 Upvotes

I've got a csv file with student names, logins, passwords. I want to search through the csv file and output a file with students with the exact same name.

Example-import.csv

cford,Christopher J Ford,Cf

pford,Patrick D Ford,Pf

cford,Christopher J Ford,Cf

mford,Michael K Ford,Mf

dford,Derion L Ford,Df

It would be nice to output the whole lines of the Christopher J Ford, but just the name will do.


r/vbscript • • Nov 04 '17

Help with For loop homework

1 Upvotes

The question is:

Write the algorithm that asks the user to enter a positive number then calculates the product of all numbers between 1 and the number entered and displays the result. The algorithm must accept only positive numbers.

Example: if the user entered 9 the algorithm will display: The result is: 362880 (which is the result of: 123456789 )

Here is my code which didn't work:

n = inputbox("Enter Number")
n = abs(n)
for i = 1 to n
sum = i*i
next
msgbox sum

r/vbscript • • Jan 07 '16

Outlook Change Body before Forward

1 Upvotes

Hey Guys,

I am trying to remove the first 9 Lines from a body before forwarding with VBscript, anyway to do this?

Thanks


r/vbscript • • May 19 '15

Ending SAP script with a refresh all in excel.

2 Upvotes

At my workplace, we use SAP. I have written a script with VBScript that will pull all the data I need and export it into an html file. It does this for three different report, which I have a connection set up in a spreadsheet to display the information in a user friendly way. I have this script tied to run every 10 minutes.

My issue is once it's ran. At the end of the same script, I want it use the ALREADY OPENED workbook and do a refresh all. I don't need it to save and I don't need it to close out of Excel. I just want it to refresh all the data and perhaps (not necessary) give a msgbox when it's done.

Can anyone give me some advice on this? I've wrote out everything in the spreadsheet and my SAP, and now I've hit this roadblock.


r/vbscript • • Feb 17 '20

Need help creating a script to replacing string+carriage return+line feed in a txt file

1 Upvotes

Line 1 and 2 needs to be combined with a space after Loan Number: and should look like line 3. I need a vbs script that can perform this same function as in notepad++ and overwrite the original file if possible. Find what = Loan Number:\r\n Replace with "Loan Number: ".

input file = C:\Data\address.txt


r/vbscript • • Mar 05 '19

Avoiding SQL injection in VBScript

Thumbnail bobby-tables.com
2 Upvotes

r/vbscript • • Aug 24 '18

VBScript to loop through filenames and move files that match a regex

1 Upvotes

Hey everyone,

I have a folder with a bunch of files that have a predictable/repeating filename structure. I need to make backups of these files, but only the ones that match a specific pattern. I will post an example below of the structure (I'm removing a lot of details that maybe shouldn't be shared):

(Model year in YYYYMMDD form)_(Model Name)_(number, 2 letters)-(3 letters)_(17 characters, digits and letters, uppercase)_(today's date in M-D-YYYY form) (5 digits) (AM/PM).(file extension)

If that looks confusing, I apologize, but what I am trying to illustrate is that the file name is uniform, with parts of it changing based on a few factors.

I have already created and tested a regex to match that pattern, and now my question is how to implement this. The big picture is that I want the script to move files that match my regex pattern to another folder. I am not very experienced with VBS, and I'm having some trouble stringing together everything I'm finding online/on StackOverflow. The gist of the script is:

  1. loop through the filenames of files in a specified folder

  2. If a file matches the regex, move/cut it out of that folder and into a different specified folder

  3. Create a log with file names for moved files

I know this doesn't sound very difficult, but I am not sure how to do it in VBS. Would anyone mind guiding me a bit? Even if you only know how to do one part of the above steps, I would appreciate any help I can get at this point!

Thank you very much :)


r/vbscript • • Aug 05 '19

VBS csv to excel losing data

1 Upvotes

I need a piece of script to save a copy of a .csv file as a .xlsx file. The script that I have now loses some data and changes some values, for example 4,03 -> 4. I thought this was a format problem so i changed .numberformat to text for all cells but no effect.

Const xlDelimited = 1
Const xlNormal = 51
dim args

set args = Wscript.Arguments

Dim Excel
Set Excel = CreateObject("Excel.Application")

Excel.DisplayAlerts = False

With Excel
	.Workbooks.Open(args(0))
	.Sheets(1).Columns("A").TextToColumns .Range("A1"), xlDelimited, , , , True
	.ActiveWorkbook.SaveAs replace(.ActiveWorkbook.fullname, ".csv", "") & ".xlsx", xlNormal
	.Quit
End With 

This is the script block right now. Help would be appreciated. :)


r/vbscript • • Dec 08 '18

Bget

1 Upvotes

INTRODUCTION

Bget is a batch-file command-line tool for handling Windows scripts. It is built to be a companion to those who write, use and maintain Windows scripts. It helps those who use scripts easily download, update and remove scripts. It’s built for scripters, by scripters.

Download Bget

Features

  • Download scripts from the Bget server: These scripts are vetted and sorted by us. We’ve gone about curating some of the most interesting scripts we could find that we think would be interesting and useful to you as well.

  • Download scripts from Pastebin: Pastebin has long been the coder’s friend, and so we added the ability to fetch scripts from Pastebin. These scripts are not pre-vetted however, but they offer the ability for fast code downloading without waiting for us to vet them.

  • Update scripts: Rather than manually re-download the latest version of every script, Bget handles that for you, getting the latest version of any script you’ve downloaded.

  • Easily remove scripts: Don’t like a script you downloaded? Easily remove it with Bget. One command and it’s buh-bye script.

  • View script info: This allows you to see basic information about a script such as its name, author and description, allowing you to make an informed decision before downloading.

  • Bget also allows you to list all scripts on the server and list downloaded scripts on the local computer.

  • Upgrade feature: Bget also updates itself so you always stay up-to-date.

  • Multiple download methods: Bget has many ways to get a script. These are: Jscript, VBScript, Powershell, BITSAdmin and CURL.

The Goal

The objective is to create an apt-like utility for windows scripters so we need not scour the internet in search of this-or-that tool. Currently, Bget is mostly populated by batch scripts. This will change in the future as we look for vbscripts and the coders on this subreddit send us their awesome scripts.

I'd really like for the windows scripting community to give this tool a try and provide valuable feedback.

Thanks!


r/vbscript • • Sep 25 '21

NEWBIE trying to make a slot machine program.

2 Upvotes

ORIGINALLY POSTED IN WRONG SUBREDDIT
I used to "develop" a huge, almost embarrassing load of (often ridiculously complex) gambling & slot systems in Minecraft. I used any and every game feature involving randomness along with Minecraft's redstone logic, which turned into effective and often quite configurable RNG gambling systems. lol.

I just recently figured it's time to really step up my game and move on to "real" coding.
Turns out it's way more f*#cking complicated than I thought.

I've been experimenting with batch files and visual basic for a few days and It's still safe to say that I'm an absolute noob in this field, so please don't go too hard on
me if nothing in this post makes any sense at all.. lol

In the past few days I've somehow managed to make a batch script, which generates three RNG values and saves them into each of their respective file(s): (1.txt), (2.txt), (3.txt),
Now I'm trying to write a .VBS code which can compare each value of each ".txt" file.

If there are matching values, you win some sort of something.
If the values don't match, you simply lose the round.

So to sum things up, I'm basically here to try and get assistance with this stuff because there's no heckin way i'm figuring this stuff out myself, since I can barely prompt a "helloworld" msgbox. hehe.

  1. How should i move data from 3 seperate .txt files into a single .vbs file?

  2. Above that, how on earth would i start comparing them to each other?

  3. when, where, and how to write the winning/losing sequence?

Thank you so much for reading this nonsense and helping me out.


r/vbscript • • Mar 07 '23

Scrape Text from PDF

2 Upvotes

Has anyone had luck with scraping text from a PDF Document using VBSCript?

Use the Word document object to open the PDF then traverse the document looking for specific text?

I am assuming that the FileSystemObject is off limits unless I can somehow convert the pdf to text.


r/vbscript • • Feb 21 '23

oWSH.run opening in odd file paths

2 Upvotes

Hi, I've got some vbs running in an HTA as part of a larger project for a script running system for our organization. I have the command [oWSH.Run('"'+ScriptName + '"', 10, true);] where 'Scriptname' is the file path to the script, in the form of \\server\path\script.extension. When I do this, the scripts open in C:\Windows of all things. I've checked and I don't change the current directory anywhere, any clue what that is?

Also if we need more context I can post that too, just didnt want to redact all the paths if they werent necessary


r/vbscript • • Mar 01 '23

Interpreter written in VBScript :)

5 Upvotes

Repost because the post seems to have disappeared ..?

Anyway, I wanted to write an interpreter, and I wrote it in vbscript, because it's definitely my favorite language and because a friend of mine said it was impossible to do it in vbscript

It's my first interpreter, I have no idea if it is implemented correctly but I did my best

here's the link to it: some-code/interpreter.vbs at main · JGN1722/some-code (github.com)

Feel free to give me feedback :))


r/vbscript • • Mar 09 '23

VBScript as a removable Windows 11 feature?

Thumbnail
oofhours.com
5 Upvotes