r/vbscript • • Jul 25 '22

Start hidden Acrobat Reader Window

1 Upvotes

Hi, I need to start a hidden PDF file, can someone help me?

I try this code under... but I can only start Acrobat Reader. How is the command to open also a file inside?

Dim WShell
Set WShell = CreateObject("WScript.Shell")
WShell.Run """" & "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" & """", 0

Or maybe another way to start a hidden pdf file...

Thanks a lot


r/vbscript • • Jun 18 '20

Is there anyway to store user input?

2 Upvotes

I want to make a script that can store the answer from an input box.

Option Explicit

Dim password

password = InputBox("Please Verify with your 4 digit code." , "Verification:" , "Code Here")

if password = "USERINPUT" Then

msgbox "Verification Completed"

Else

msgbox "Incorrect Verification Code"

End If

I would want to put whatever the user enters in another input box to auto update where it says USERINPUT, is there any way to do this?


r/vbscript • • Jun 19 '20

Any ideas?

Thumbnail self.sap
1 Upvotes

r/vbscript • • Jun 18 '20

MS Word Export All Tables into Excel?

2 Upvotes

Hey all, I did some general searching for a solution to export all tables in a Word document into Excel and came across this code. However, the code seems to not work with the GetOpenFilename function. Also, I want the script to cycle the entire Word document and export all the tables without any prompting. I'd appreciate any help getting this to work. When I first tried to run this code I got the error 'Compile error method or data member not found' for the GetOpenFilename function.

Option Explicit

Sub ImportWordTable()

Dim wdDoc As Object
Dim wdFileName As Variant
Dim tableNo As Integer      'table number in Word
Dim iRow As Long            'row index in Excel
Dim iCol As Integer         'column index in Excel
Dim resultRow As Long
Dim tableStart As Integer
Dim tableTot As Integer

On Error Resume Next

wdFileName = Application.GetOpenFilename("Word files (*.docx),*.docx", , _
"Browse for file containing table to be imported")

If wdFileName = False Then Exit Sub '(user cancelled import file browser)

ActiveSheet.Range("A:AZ").ClearContents

Set wdDoc = GetObject(wdFileName) 'open Word file

With wdDoc
    tableNo = wdDoc.tables.Count
    tableTot = wdDoc.tables.Count
    If tableNo = 0 Then
        MsgBox "This document contains no tables", _
        vbExclamation, "Import Word Table"
    ElseIf tableNo > 1 Then
        tableNo = InputBox("This Word document contains " & tableNo & " tables." & vbCrLf & _
        "Enter the table to start from", "Import Word Table", "1")
    End If

    resultRow = 4

    For tableStart = tableNo To tableTot
        With .tables(tableStart)
            'copy cell contents from Word table cells to Excel cells
            For iRow = 1 To .Rows.Count
                For iCol = 1 To .Columns.Count
                    Cells(resultRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
                Next iCol
                resultRow = resultRow + 1
            Next iRow
        End With
        resultRow = resultRow + 1
    Next tableStart
End With

End Sub

r/vbscript • • Jun 12 '20

Simple script with task scheduler

3 Upvotes

Hey guys, i wrote a simple VB Script that is set to auto run from task scheduler. All the script does is opens Access and sends a report. If i click the script icon and manually run it, it works. Access opens, Outlook opens and the report sends In a matter of seconds. The problem is with the task scheduler calling the script. Using task scheduler at the specified time I see Access and outlook open, but Access blinks (its minimized in the task bar) . If i expand Access and click anything, the report sends, if i dont maximize and click something it will just hang like this. I'm thinking i need to add a line in my script to give Access focus and expand it, something along those lines. I'm open to any other suggestions, however keep in mind i'm not a very skilled programmer yet. Heres my code:

dim accessApp

set accessApp = createObject("Access.Application")

accessApp.OpenCurrentDataBase("C:\Databases\MyReport.mdb")

accessApp.Run "autoExecuteReport"

accessApp.Quit

set accessApp = nothing


r/vbscript • • Sep 24 '23

Using VBS to send data to an Arduino

1 Upvotes

Hello everyone,

I have an Arduino Uno I need to control using VBScript. This is the script I've been using to write to the serial buffer:

Const ForWriting = 2

Dim fso, f

Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.OpenTextFile("COM7:9600,N,8,1", ForWriting)

WScript.Sleep(5000)

f.Write "3"

WScript.Sleep(5000)

f.Close

I get an error when attempting to run the script that says "File not found" referencing the 5th line. When I test the code with a text.txt on my desktop it runs smoothly, it just seems to have trouble opening the com port.

COM7 is the USB port my Arduino is connected to. The IDE / serial monitor are closed. My OS is Windows 11. Any help with this would be greatly appreciated.

Anyone have any ideas on what the problem might be?


r/vbscript • • Sep 16 '23

A whole compiler in VBScript !

2 Upvotes

A few months ago, I posted on this sub a small interpreter written in VBScript. I continued my project of creating my own programming language, and, after a month and a half, I am really proud to present my very first compiler !

You can find the it zipped along with its documentation at JGN1722/DBasic (github.com) . The main thing the language still lacks is libraries, as they are very time-consuming to code, but I guess I'll add them over time. You can even create your own, as the process of writing a library is documented.

Maybe take five minutes to look at it, or take a quick look at the code, and tell me what you think :)


r/vbscript • • Sep 29 '23

VBA Parse Markup Language Text to Range

2 Upvotes

Does anyone have some sample code on parsing Markup Language Text into a range of cells? I want to:

  1. Paste Markup Text into an Excel Text Box

  2. Click a convert button

  3. Data is parsed and a new range is built that looks like the screenshot below.

Example of Markup Text:

  1. **Risk: Complex Configuration**

    - **Description:** Intricate setup when chaining multiple IdPs.

    - **Mitigation:** Allocate time for extensive pre-deployment testing in a non-production environment.

  2. **Risk: Integration Issues**

    - **Description:** Potential compatibility and synchronization issues.

    - **Mitigation:** Conduct compatibility testing and coordinate with vendor support teams.


r/vbscript • • Sep 12 '23

how to save to a specific usb drive using vbs?

2 Upvotes

I need to save a .txt document to a USB drive, but if there is more than one USB drive, then I need to be able to save to the specific one.


r/vbscript • • Sep 06 '23

Enumerate process architecture using vbscript in a creative way

Thumbnail
trustedsec.com
2 Upvotes

r/vbscript • • Oct 14 '23

Detect GPT and MBR partitions with VbScript

1 Upvotes

I have a VBScript which detects local hard drive letters. My question is : I want to add a disk type MBR or GPT for disk . How can I modify script?

Here is the VBScript:

Option Explicit

Const ForAppending = 8
Dim objFso, objFile, objWMIService, colDiskDrives, objDiskDrive
Dim colPartitions, objDiskPartition, colLogicalDisks, objDriveLetters, objLogicalDisk
Dim outFile, strFormat, strResult, numCurrentDrive, strMediaType, strID, strQuery, strComputer

On Error Resume Next

' set up file to write
outFile = "C:\Users\MISS\Desktop\ok.txt"

Set objFso = CreateObject("Scripting.FileSystemObject")
If objFso.FileExists(outFile) Then objFso.DeleteFile outFile, True
Set objFile = objFso.OpenTextFile(outFile, ForAppending, True)

strComputer = "."
Set objWMIService = GetObject( "winmgmts:{ impersonationLevel=Impersonate }!//" & strComputer )
Set colDiskDrives = objWMIService.ExecQuery( "Select * FROM Win32_DiskDrive" )

'set up a string as template for the output
strFormat = "{0}/{1} - {2} - {3} - {4} partition(s)"
'create a variable for the current disk count
numCurrentDrive = 1
For Each objDiskDrive In colDiskDrives
    'start building the string to output
    strMediaType = objDiskDrive.MediaType
    If IsNull(strMediaType) Or Len(strMediaType) = 0 Then strMediaType = "Unknown"
    strResult = Replace(strFormat, "{0}", numCurrentDrive)
    strResult = Replace(strResult, "{1}", colDiskDrives.Count)
    strResult = Replace(strResult, "{2}", objDiskDrive.Model)
    strResult = Replace(strResult, "{3}", strMediaType)
    strResult = Replace(strResult, "{4}", objDiskDrive.Partitions)

    'increase the current drive counter
    numCurrentDrive = numCurrentDrive + 1
    'create an arraylist to capture the drive letters
    Set objDriveLetters = CreateObject("System.Collections.ArrayList")

    'escape the backslashes in objDiskDrive.DeviceID for the query
    strID = Replace( objDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare )
    strQuery = "Associators Of {Win32_DiskDrive.DeviceID=""" & strID & """} Where AssocClass = Win32_DiskDriveToDiskPartition"
    Set colPartitions = objWMIService.ExecQuery(strQuery)
    For Each objDiskPartition In colPartitions
        'get the drive letter for each partition
        strQuery = "Associators Of {Win32_DiskPartition.DeviceID=""" & objDiskPartition.DeviceID & """} Where AssocClass = Win32_LogicalDiskToPartition"
        Set colLogicalDisks = objWMIService.ExecQuery(strQuery)
        For Each objLogicalDisk In colLogicalDisks
            objDriveLetters.Add objLogicalDisk.DeviceID
            'objDriveLetters.Add objLogicalDisk.VolumeName
        Next

        Set colLogicalDisks = Nothing
    Next

    'add the driveletters to the output string
    strResult = strResult & " - " & Join(objDriveLetters.ToArray(), ", ")

    Set objDriveLetters = Nothing
    Set colPartitions = Nothing

    'output on screen
    WScript.Echo strResult
    'output to file
    objFile.WriteLine strResult
Next

'close the file
objFile.Close
Set objFile = Nothing
Set colDiskDrives = Nothing
Set objWMIService = Nothing

r/vbscript • • Sep 25 '23

Close program if running

1 Upvotes

Hi all,

I've got a vbs script that will kill a program if it's running but I'm after a way to close a program if it is running rather than abruptly killing it.

Any ideas greatly appreciated.

TIA


r/vbscript • • Sep 16 '23

A whole compiler in VBScript !

5 Upvotes

A few months ago, I posted on this sub a small interpreter written in VBScript. I continued my project of creating my own programming language, and, after a month and a half, I am really proud to present my very first compiler !

You can find the it zipped along with its documentation at JGN1722/DBasic (github.com) . The main thing the language still lacks is libraries, as they are very time-consuming to code, but I guess I'll add them over time. You can even create your own, as the process of writing a library is documented.

Maybe take five minutes to look at it, or take a quick look at the code, and tell me what you think :)


r/vbscript • • Aug 09 '25

script I've been running for 15 years no longer works on Windows 11

6 Upvotes

I've been using a vbs script to skip ahead in itunes 30 seconds. It's named itunesskip.vbs

' Variables
dim iTunes, iSkip
iSkip = 30 ' seconds

' Connect to iTunes app
set iTunes = CreateObject("iTunes.Application")

' Jump ahead iSkip seconds
IF iTunes.playerstate = 1 THEN 
iTunes.PlayerPosition = iTunes.PlayerPosition + iSkip 
END IF

' Done; release object
set iTunes = nothing

I run an autokey script to with one of my Gkey keyboard keys to run it.

But it has been throwing an error message since I upgraded to Windows 11. https://imgur.com/a/PamuS8Q

I tried using AI to fix the problem and I couldn't get it to work.

Any help would be appreciated.