From: Justin on
Hello,

I have an issue pertaining to opening Excel password protected files via Matlab. I was wondering if there is a way to pass the password when opening a password protected excel file in Matalb? Any help with this would be greatly appreciated.

Thanks,
Justin
From: Andy on
"Justin " <rothj070(a)gmail.com> wrote in message <i27i82$3fa$1(a)fred.mathworks.com>...
> Hello,
>
> I have an issue pertaining to opening Excel password protected files via Matlab. I was wondering if there is a way to pass the password when opening a password protected excel file in Matalb? Any help with this would be greatly appreciated.
>
> Thanks,
> Justin

doc actxserver

The Open method of the Workbooks object takes a password as an argument. So something close to the following should work:

[fn pn] = uigetfile('*.xls');
passwd = 'yourpassword'; % don't actually store your password in the mfile like this
e=actxserver('excel.application');
eW = e.Workbooks;
eF = eW.Open([pn fn],passwd);

Note: this is untested, as I am currently away from MATLAB.
From: Justin on
"Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i27itk$ghg$1(a)fred.mathworks.com>...
> "Justin " <rothj070(a)gmail.com> wrote in message <i27i82$3fa$1(a)fred.mathworks.com>...
> > Hello,
> >
> > I have an issue pertaining to opening Excel password protected files via Matlab. I was wondering if there is a way to pass the password when opening a password protected excel file in Matalb? Any help with this would be greatly appreciated.
> >
> > Thanks,
> > Justin
>
> doc actxserver
>
> The Open method of the Workbooks object takes a password as an argument. So something close to the following should work:
>
> [fn pn] = uigetfile('*.xls');
> passwd = 'yourpassword'; % don't actually store your password in the mfile like this
> e=actxserver('excel.application');
> eW = e.Workbooks;
> eF = eW.Open([pn fn],passwd);
>
> Note: this is untested, as I am currently away from MATLAB.

I ran the code and I get the following error:

??? Invoke Error, Dispatch Exception:
Source: Microsoft Office Excel
Description: Open method of Workbooks class failed
Help File: C:\Program Files\Microsoft Office\Office12\1033\XLMAIN11.CHM
Help Context ID: 0

Error in ==> testpwdprotect at 5
eF = eW.Open([fn pn],passwd);

Essentially I would like to be able to open this workbook, which is stored on a server, without prompting the user and then use xlswrite to write to and save the workbook.
From: Andy on
> Error in ==> testpwdprotect at 5
> eF = eW.Open([fn pn],passwd);

Note the order of the path name and file name.
From: Andy on
"Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i29e1j$6ti$1(a)fred.mathworks.com>...
> > Error in ==> testpwdprotect at 5
> > eF = eW.Open([fn pn],passwd);
>
> Note the order of the path name and file name.

Alright, I finally had a chance to try it out. The following worked for me:

eF=eW.Open([pn fn],[],false,[],'pass');

Note: I typed the password into a string. But it's generally not the best idea to have your passwords hard coded into an m-file.