Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can I open a password protected xls file?

1,962 views
Skip to first unread message

Michael Gao

unread,
Feb 26, 2009, 10:13:33 PM2/26/09
to
Hi,
I have an Excel file with password protected and I know the password. How
can I change the script to open it without prompt my password?

$a = New-Object -ComObject Excel.Application
$a.Visible = $True
$a.DisplayAlerts = $False
$a.workbooks.open("d:\out\book1.xlsx")|out-null

Thanks.
MG

Marco Shaw [MVP]

unread,
Feb 27, 2009, 3:28:27 PM2/27/09
to

Are you willing to use something 3rd party like AutoIt
(http://www.autoitscript.com/)?

You need a way to automate the writing of text to a particular window...

Marco

Joel Bennett

unread,
Feb 27, 2009, 11:10:43 PM2/27/09
to
That's actually trivial ...

$missing = [System.Reflection.Missing]::Value

$a.Workbooks.Open( "d:\out\book1.xlsx",
$missing, $missing, $missing,
"readPassword", "writePassword" )
--
Joel

Shay Levy [MVP]

unread,
Feb 28, 2009, 6:28:50 AM2/28/09
to
Hi Michael,

This will open a protected password file with a read/write password of "shay",
tested on Excel 2007:

$xl = New-Object -com Excel.Application
$xl.visible=$true
$xl.Workbooks.open("D:\pass.xls",1,$false,5,"shay","shay")


You can get help on the Workbooks.Open Method, paste the following to the
run dialog and press enter:
ms-help://MS.EXCEL.DEV.12.1033/EXCEL.DEV/content/HV10063099.htm

---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar

MG> Hi,
MG> I have an Excel file with password protected and I know the
MG> password. How
MG> can I change the script to open it without prompt my password?
MG> $a = New-Object -ComObject Excel.Application
MG> $a.Visible = $True
MG> $a.DisplayAlerts = $False
MG> $a.workbooks.open("d:\out\book1.xlsx")|out-null
MG> Thanks.
MG> MG


Marco Shaw [MVP]

unread,
Feb 28, 2009, 7:17:56 AM2/28/09
to

> Are you willing to use something 3rd party like AutoIt
> (http://www.autoitscript.com/)?
>
> You need a way to automate the writing of text to a particular window...
>
> Marco

I never checked the open method, and whether it supported extra values.
The others have pointed out a much better method.

Marco

Josh Einstein

unread,
Feb 26, 2009, 10:25:23 PM2/26/09
to
I would recommend asking in the Excel or VSTO group, but it may not be
possible. Office automation is not ideal for non-interactive use and lots of
methods simply always produce a UI.

Josh

"Michael Gao" <gaoy...@hotmail.com> wrote in message
news:ekIDjlIm...@TK2MSFTNGP03.phx.gbl...

Michael Gao

unread,
Mar 3, 2009, 2:10:14 AM3/3/09
to
$xl.Workbooks.open("D:\pass.xls",1,$false,5,"shay","shay") is working fine.
That's what I needed.

Thanks!
MG


"Shay Levy [MVP]" <n...@addre.ss> wrote in message
news:95d808936e85c8...@news.microsoft.com...

0 new messages