Batch commands to open password protected excel file


  1. Posts : 12
    windows 10
       #1

    Batch commands to open password protected excel file


    I'd like to speed up the process of opening several programs among which there is a password protected excel file, this is the line I'd use to open the excel file/program in the batch file:

    start /D "C:\Users\Name\Desktop\Folder" excelfile.xlsx

    that command opens excel and the file but the most important part is missing: what command is it available to input the password for the file?
      My Computer


  2. Posts : 831
    Windows 7
       #2

    There is no command, it requires VBA or VBS scripting.

    Try this short VBS script, it accepts a list of Excel filenames and opens them using the same password. Unlike PowerShell, VBS is terrible about relative file paths like if you're opening "Book1.xlsx". This script assumes if you didn't provide a full path, the given filename or path is relative to the current folder.

    OpenPassword = password to open Excel file
    WritePassword = (Optional) password to allow writes

    If there is no write protection on the file, then update WritePassword = ""

    wscript PasswordExcel.vbs C:\Users\GARLIN\Downloads\Book1.xlsx Book12.xlsx

    PasswordExcel.vbs
    Code:
    OpenPassword = "12345678"
    WritePassword = "12345678"
    
    Set objArgs = Wscript.Arguments
    
    If (objArgs.Count > 0) Then
        Set objExcel = CreateObject("Excel.Application")
    
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        CurrentDir = objFSO.GetAbsolutePathName(".")
    
        For Index = 0 to (objArgs.Count - 1)
             ExcelFile = objArgs(Index)
             If (InStr(ExcelFile,":\") = 0) Then
                  ExcelFile = CurrentDir + "\" + ExcelFile
             End If
    
             If IsNull(WritePassword) Then
                 Set objWB = objExcel.Workbooks.Open(ExcelFile,,,,OpenPassword)
             Else
                 Set objWB = objExcel.Workbooks.Open(ExcelFile,,,,OpenPassword,WritePassword)
             End If
        Next
        objExcel.Application.Visible = True
    End If
      My Computer


  3. Posts : 17,015
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #3

    wosxis said:
    what command is it available to input the password for the file?
    You might as well remove the password as use a script to enter it because any script will need to contain the unencrypted password [as illustrated by garlin above].


    wosxis said:
    this is the line I'd use to open the excel file/program in the batch file:
    start /D "C:\Users\Name\Desktop\Folder" excelfile.xlsx
    Just use
    C:\Users\Name\Desktop\Folder\excelfile.xlsx
    [assuming that's the full path to excelfile]
    because that will open the file in Excel.



    Denis
      My Computer


  4. Posts : 65
    Windows 10
       #4

    wosxis said:
    I'd like to speed up the process of opening several programs among which there is a password protected excel file, this is the line I'd use to open the excel file/program in the batch file:

    start /D "C:\Users\Name\Desktop\Folder" excelfile.xlsx

    that command opens excel and the file but the most important part is missing: what command is it available to input the password for the file?
    From the command line, if you just supply the Excel document, it will use the Windows OpenWith function, and that one probably doesn't know of parameters and such, it's just : start application with that file, that's it.

    But, if you launch Excel itself, the .exe (or whatever it is that is needed to start with), the specific runnable command MAY accept parameters. It's always a good test to find out how command line friendly a program is.

    Google will tell you this, I just presume it's Excel.exe but it can be anything really.

    Some commands have tons of parameters. Some have none. So, if you're lucky, there may be one, and there may be one to accept passwords ... but it must be said, password parameters are special, in the way that these should not be printed at all.

    Check this out:
    https://support.microsoft.com/en-gb/...Category=Excel
      My Computer


  5. Posts : 831
    Windows 7
       #5

    Office apps don't support file passwords on the command line, for the obvious security reasons. You can snoop a running process' command-line arguments, but a VBScript launching an Excel object doesn't reveal anything.
      My Computer


  6. Posts : 65
    Windows 10
       #6

    garlin said:
    Office apps don't support file passwords on the command line, for the obvious security reasons. You can snoop a running process' command-line arguments, but a VBScript launching an Excel object doesn't reveal anything.
    So, short: you can in a VBS script, but Microsoft itself can't.
      My Computer


  7. Posts : 831
    Windows 7
       #7

    That's how MS has always intended it to work. There's a huge world of Office-based script programming out there, it's highly specialized and amazing what those people can do. It's an entire rabbit hole to explore.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 22:49.
Find Us




Windows 10 Forums