Jump to content

Open Excel password protected file with batch script

I'd like to speed up the process of opening several programs among which there is a password protected excel 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 there to input the password for the file?

Link to post
Share on other sites

1 hour ago, Eigenvektor said:

Here's a way to do it with a PowerShell script:

https://stackoverflow.com/a/59273290

in this case I'd have to change the other lines of commands to open the other programs (without passwords), isn't it possible to input the excel password in a bat file?

Link to post
Share on other sites

Just now, ratiw said:

in this case I'd have to change the other lines of commands to open the other programs (without passwords), isn't it possible to input the excel password in a bat file?

You can pass arguments to PowerShell scripts, just like you'd do with a batch script

$path = $args[0]
$password = $args[1]
$excel = New-Object -ComObject Excel.Application
$workbook = $excel.Workbooks.Open($path,$false,$false,5,$password)
$excel.Visible = $true

 

powershell -file OpenExcel.ps1 "c:\temp\1.xls" "123"

 

You should be able to add some if-statement in there to open the file without a password if none is present, or maybe you can simply leave the second argument empty if none is required

Remember to either quote or @mention others, so they are notified of your reply

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×