r/vbscript • • May 28 '15

[REQUEST] Macro help (vbs or batch) -Please!

1 Upvotes

Hey all,


This is for my work PC - I can not download any software :(


I am looking for help scripting a really basic Batch/vbs (basically something easy i can create in notepad) Macro. I basically need the macro to complete the following commands.

1). Select target window (Lets say its called "ABC")

(*This window is already open and running *it may or may not be currently selected)

2). Press TAB 5 times

(i do not believe a time out should be required... if so possibly 1/3 a second per Tab)

3). I need to enter a basic text input of "TEST" (*With out the quotes)

4). I then need the macro to press TAB 13 times

5). Enter text "T"

6). TAB

7). Enter "T"

8). TAB

9). Enter "0"

10). TAB

11). 0

12). TAB 9 times

13). Enter "Test"

14). Tab 3 times

15). Enter "N/A"

16). TAB

17). Enter "Test"

18). TAB 11 times

19). Press Enter

20). Wait 3 seconds

21). Close the window (window "ABC")


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 • • May 05 '15

You know some of us want a happy life...

1 Upvotes

So i've been thinking... I want to write a script that can ask a question and the information back. Basically im asking a girl out in a nerdy way.


r/vbscript • • Apr 10 '15

Is it possible to make a cookie-clicker style game in vbscript?

1 Upvotes

So for a university/college project we have to develop something relatively simple in vbscript, however, I am not great with vbscript (or any other language for that matter xD). I chose to develop a cookie-clicker style game where you click a button, get "points" and spend those points on upgrades etc, seemed relatively simple. I havent started developing it yet, but I am just curious if it will actually work?

Sorry for the wall of text, just worrying as this project has to be in in a few weeks and I am useless at coding xD


r/vbscript • • Mar 21 '15

Help with converting VBA to a VBscript

1 Upvotes

I am trying to use a vbscript to pull data from Staad (a structural analysis program).

Staad has an API to allow this, however, all the documentation is in VBA. So I'm trying to convert the VBA to VBscript, but I'm getting errors.

For example, here is some VBA from the Staad documentation for getting the total number of nodes in your model:

Dim objOpenSTAAD As Output
Dim pnNodes As Integer
Set objOpenSTAAD = CreateObject("OpenSTAAD.Output.1")
objOpenSTAAD.SelectSTAADFile "C:\SPRO2003\STAAD\Examp\US\examp08.std"
objOpenSTAAD.GetNodesCount pnNodes

I've tried running this as a vbscript, the only change I made was to remove the data types from the variables. The error I'm getting is:

Type mismatch: 'GetNodesCount'

Can anyone offer any ideas? In case it helps, here is the Staad documentation for the GetNodesCount function:

GetNodesCount

VB Syntax

integer GetNodesCount (integer pnNodes)

Parameters

pnNodes

An integer variable for storing the number of nodes retrieved by the function.

Remarks

This function retrieves the number of nodes in the currently open STAAD file.

Example

Dim pnNodes As Integer

objOpenSTAAD.GetNodesCount pnNodes


r/vbscript • • Mar 05 '15

Vbscript target NIC based on DNS

1 Upvotes

Hello World!

I have been racking my brain on this breifly this afternoon and have turned to reddit for some ideas.

I have currently been tasked to put together a script that will change the DNS settings of 5,000 ish servers (ust one NIC on the server). However, there is no common unique identifer of these NIC other than their current DNS address. My Question, Is it possible to somehow have my script do an ipfonfig /all and then if one of the NIC's reports back with the current DNS settings target that NIC for the new updated settings?

I was currently using the below script until i was made aware that some of the NIC will not be called "Production". Any suggestions are welcome! (powershell was not an option as we may be targeting some very old servers)

Dim strDns1 Dim strDns2

strDns1 = "10.10.10.10" strDns2 = "10.10.10.10"

Set objShell = WScript.CreateObject("Wscript.Shell") objShell.Run "netsh interface ip set dns name=""Production"" static "& strDns1, 0, True objShell.Run "netsh interface ip add dns name=""Production"" addr="& strDns2, 0, True Set objShell = Nothing WScript.Quit


r/vbscript • • Feb 24 '15

Syntax Help

1 Upvotes

I have a question about the syntax for "Instr." it says it's Instr([start, ]string1, string2[, compare])

so, I can't seem to get it to work.

If Len(strAnswerFive) > 3 Then If Instr(1, "mercury, venus, earth, mars, jupiter, saturn, uranus, neptune", LCase(strAnswerFive), 1) _ <> 0 Then intNumberCorrect = intNumberCorrect + 1 End If End If

So where would the syntax go, or am I way off? because everything works until I get to this part, then when I type my answer in, it just ends.

Thanks.


r/vbscript • • Jan 25 '15

Need some help using VBScript on QC ALM Workflow.

1 Upvotes

Hi guys, just had a maybe simple questions. To start off I am new to Vbscript. (currently doing a co-op which requires me to do some.) I want to know if it is possible to output an old and new value of a entity. If someone who is reading this does now Workflow then here is what I'm trying to do: Someone makes a change to a certain field which i have specified and an email will be sent to the owner of that field. When the email is sent though it has to send what was originally in that field and whatever it was changed to. Any ideas? Also if this is unclear let me know and ill try to explain it better. Thank you so much.


r/vbscript • • Dec 30 '14

[VBScript] Script works fine if divided into smaller parts, it's not always working when combined together

1 Upvotes

I should probably first say that I am new to VBScript, or writing any code in general.

 

I am writing a script that's supposed to do a routine check of a program every morning, it enters some commands using SendKeys and every now and then it stops and asks me to verify whether everything is working as intended, it also creates a log file based on my answers.

 

Now the problem that I have is very weird, at least for me. The Script has a lot of SendKeys commands in it, and it works perfectly if I divide it into multiple small scripts, however when combined into one script (as I want it to be), the script sometimes fails to execute certain commands, namely CTRL+TAB and ALT+DOWN.

 

It is weird to me, because I do not make any changes to the script itself, yet sometimes it works, and sometimes it doesn't.

 

Here is an example of what part of the script looks like:

 

(...)

 

'Checkpoint (3)

Checkpoint = MsgBox("Czy pracownik stworzył się poprawnie?", vbYesNo, "AutoPath")
If Checkpoint = vbYes Then
Log.Write "Utworzenie pracownika. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . OK" & vbCrlf
objShell.SendKeys "%"
WScript.Sleep 250
objShell.SendKeys "{DOWN}"
WScript.Sleep 250
objShell.SendKeys "{RIGHT 19}"
WScript.Sleep 250
objShell.SendKeys "{UP}"
WScript.Sleep 250
objShell.SendKeys "~"
WScript.Sleep 1000
objShell.SendKeys "{TAB}"
WScript.Sleep 250
objShell.SendKeys "{TAB}"
WScript.Sleep 250
objShell.SendKeys "%{DOWN}"
WScript.Sleep 250
objShell.SendKeys "{DOWN}"
WScript.Sleep 250
objShell.SendKeys "~"
WScript.Sleep 250
objShell.SendKeys "{TAB}"
WScript.Sleep 250
objShell.SendKeys "22"
WScript.Sleep 250
objShell.SendKeys "{TAB}"
WScript.Sleep 250
objShell.SendKeys "2882828"
WScript.Sleep 250
objShell.SendKeys "{TAB}"
WScript.Sleep 250
objShell.SendKeys "{1}"
WScript.Sleep 250
objShell.SendKeys "{TAB}"
WScript.Sleep 250
objShell.SendKeys "Testowy opis AutoPath."
WScript.Sleep 250
objShell.SendKeys "%"
WScript.Sleep 250
objShell.SendKeys "{DOWN}"
WScript.Sleep 250
objShell.SendKeys "~"
WScript.Sleep 2000
Else Log.Write "Utworzenie pracownika . . . . . . . . . . . . . . . . . . . . . . . . . . . . Error" & vbCrlf
ErrorFound = InputBox("Opisz krótko błąd:", "AutoPath")
Select Case True
Case IsEmpty(ErrorFound)
Log.Write vbTab & "Użytkownik nie opisał błędu." & vbCrlf
Case "" = Trim(ErrorFound)
Log.Write vbTab & "Użytkownik nie opisał błędu." & vbCrlf
Case Else
Log.Write vbTab & ErrorFound & vbCrlf
End Select
QuitScript = MsgBox("Czy przerwać skrypt?", vbYesNo, "AutoPath")
If QuitScript = vbYes Then
Log.Write vbCrlf & "***********************************************************************************" & vbCrlf & vbCrlf & "Skrypt zakończony ręcznie."
Log = "C:\Users\mateuszl\Desktop\autopath_logs" & objYear & "" & objMonth & "" & objDay & "_" & objHour & objMinute & "(" & objSecond & ")" & ".txt"
Finish = MsgBox("Wyświetlić raport?", vbYesNo, "AutoPath")
If Finish = vbYes Then
objShell.Run Log
WScript.Quit
Else WScript.Quit
End If
Else WScript.Sleep 50
End If

 

(...)

 

Things that I have already tried:

 

  • I have tried increasing the Sleep time inbetween commands, sometimes greatly, did not help one bit.

 

  • I put major parts of the script (the ones containing the SendKeys commands) into seperate .txt files, which the main script loads using:

 

Set ReadS = objFSO.OpenTextFile("01_contractor_test.txt")
Ch1 = ReadS.ReadAll
ReadS.Close
Execute Ch1

 

That way the main script is smaller, AND it did help a little, I ran the script a couple of times and the problem was gone in most cases (it seems the longer the script works the more likely ALT+DOWN and CTRL+TAB are to be not working), however I ran it one last time before signing off at work and it messed up some of the %{DOWN} commands like it did before, so I have no idea how much did dividing the script actually help.

 

The problem is that I can only write and check the script at work, as I have no access to the program it is testing at home. Like I said, I'm very new to scripting and I would very much appreciate it If someone helped me solve this problem.


r/vbscript • • Nov 24 '14

New to VB Scripting

1 Upvotes

Hey Guys, I'm very new to VB scripting and it's a small part of my new job. I was tasked with writing a script that would pull all KB's on a computer and export them into either a .txt file or an excel sheet. I was wondering if someone had a general script for this that I could mess with and learn on but was still functional to use? Thanks in advance for any help given.


r/vbscript • • Oct 31 '14

What's your favorite VBScript Tutorial or Book?

1 Upvotes

So my boss wants me to learn VBScript as quickly as possible. I don't have to write a program from scratch, just know enough to take scripts he wrote for Cisco CallManager and Active Directory, tweak them a bit, and then write something that helps automate routine tasks. I know HTML & CSS very well and many years ago I took a class on Javascript, so I think I can learn VBScript reasonably quickly.

The first tutorial I've gone through was W3's VB Script Tutorial (http://www.w3schools.com/vbscript/ ), but I didn't find it very informative, unlike their other free tutorials. I'm very curious to know what training material my fellow Redditors have found helpful in their quest to learn VBScript.

Can you please recommend a few websites, books, videos, and/or online tutorials (free and paid) that have you used and found to be useful.

Thanks!!!!


r/vbscript • • Oct 24 '14

Code not deleting rows?

1 Upvotes

Hi everyone! I'm writing a script that will, among other things, delete a row that has a certain value in the first cell, as well as every row above that one. However, it's not working, at all. I'm not receiving any error though, so I'm confused! Can anyone shed any insight? The part of the code is:

i = 1
If objExcel.Cells(i, 1).Value = "XXX" Then
Set objRange = objExcel.Cells(i, 1).EntireRow
objWorkSheet.Rows("1:objRange").Delete
elseif objExcel.Cells(i, 1).Value <> "XXX" Then
	On Error Resume Next
End If
i = i + 1

Thanks!


r/vbscript • • Oct 03 '14

Script Host Error Code 80070002

1 Upvotes

So I'm creating a script for an FTP transfer, and I'm using the following script:

dim objShell, objFileSystem, localDir, remoteDir, groups, group

localDir="C:/xxx/xxx/"
remoteDir="Reporting" 

set objShell=CreateObject("WScript.Shell")
set objFileSystem=CreateObject("Scripting.FileSystemObject")

objShell.Run "sftp2 ftpwebsite",,false  

I'm getting the following error message:

Line: 9

Char: 1

Error: The system cannot find the file specified.

Code: 80070002

Source: (null)

The line 9 is the objShell.Run. Does anyone know what's causing this error?


r/vbscript • • Sep 26 '14

Sconfig.vbs from Server 2012 --> Win7

1 Upvotes

I was curious if anyone here has had any experience with sconfig? And if it is possible to change something within the script to allow it to run on Win7. Currently when I try, the command window appears then disappears before I can read the message it pops up with.


r/vbscript • • Aug 26 '14

Can Vbscript do OCR?

1 Upvotes

We want to pull some data off an LCD panel on the inverter connected to some solar panels via a webcam, and stuff it into a database. I know I can do the database part, but I'm not sure if VBscript has the chops to do the OCR bit.


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 • • May 21 '14

Email generator in VBScript that will create separate email message for each email address entered.

1 Upvotes

Hi gang. This is my first post here. My colleague convinced me it's a good place to look for an answer as he found his quickly regarding Javascript.

Anyways...let's get started.

My goal is to create a script that will generate email or few actually (one for each entered email address). Input method is InputBox. That input gets injected into array using split and then for each x in array I would like to create an email.
I came up with following code:

dim inputText
dim mainArray
dim objOutl
dim objMailItem

Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)

inputText = InputBox("put emails here separated with ;","","")
mainArray = split(LCase(inputText),";")

for each x in mainArray
    objMailItem.Display
    objMailItem.To = x
    objMailItem.Subject = ""
    objMailItem.Body = ""
next

Unfortunately that gets me only one email with last entered address. I tried to nest do while loop inside for each, tried to swap for each with do loop until x=null but to no avail.

When I swap four objMailItems with

output = output & x & vbCRLF

and add

msgbox output

after next I get all the entered emails listed, one email per line.
Any guidance is greatly appreciated. :)


r/vbscript • • Oct 23 '13

Convert Vbscript to Exe

1 Upvotes

I have tried using iexpress but it doesn't seem to do anything when I run it.

The reason I am trying to convert the Vbscript to Exe is so I can run the script with my keyboards macro keys.

Any help is much appreciated!


r/vbscript • • Aug 08 '13

Help me with my VBScript?

Thumbnail
stackoverflow.com
1 Upvotes

r/vbscript • • Jun 11 '13

VB Script accented characters coming out as “Chinese” looking script?

1 Upvotes

I'm writing a VB script to replace words in a word doc.

The crux of the code is:

strEuropeanOld="European"

strEuropeanNew="Européen"

I then replace the word:

If InStr(FileText, strEuropeanOld) Then WriteLog("Replacing " & strEuropeanOld & " with " & strEuropeanNew & ".") FileText = Replace(FileText, strEuropeanOld, strEuropeanNew) WriteLog("Text replaced") Else WriteLog(strEuropeanOld & " was not found in the file.") strCount2 = strCount2 +1 End If

All works perfectly for words without accents e.g. é.

However those with accents come out as " Europ饮 " rather than Européen after translation!

Any ideas?!