From: Justin on 22 Jul 2010 11:14 "Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i29f39$dbb$1(a)fred.mathworks.com>... > "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. Thanks, Works great for opening the file. Now I have one more question. I noticed that when it opens the file I don't see it open in the Excel window. This is just fine. So I am now trying to write to the file and when I run the code that I have all matlab does is sit there. To be clear in the end I want to be able to open the file, write to it, close and save the file. Here is my code: [fn pn] = uigetfile('*.xlsm'); passwd = 'pass'; % don't actually store your password in the mfile like this e=actxserver('excel.application'); eW = e.Workbooks; eF = eW.Open([pn fn],[],false,[],passwd); xlswrite1([pn fn],'test','Sheet1','A2'); invoke(eW.ActiveWorkbook,'Save'); eW.Quit eW.delete clear e
From: Andy on 22 Jul 2010 11:52 You don't see it because when you run actxserver, Excel by default opens invisibly. If you wanted to see it, you would need to write: e.Visible = 1; There are two forms of password protection for Excel file. You can set a file to only open when a password is provided, and you can set a file to only be changeable with a password provided. It sounds like you probably have both. Probably when you run xlswrite1, an invisible password prompt pops up. Check that this is the case by making Excel visible before writing. (Also, even if you want things running invisibly in the future, it's best to validate your code with Excel visible so you can see what's going on.) If it turns out you do need a second password, then your open call needs to look like this: eF = eW.Open([pn fn],[],false,[],passwd,passwd2); If that doesn't work, post again and we can try something else.
From: Justin on 22 Jul 2010 12:08 "Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i29pf4$oao$1(a)fred.mathworks.com>... > You don't see it because when you run actxserver, Excel by default opens invisibly. If you wanted to see it, you would need to write: > > e.Visible = 1; > > There are two forms of password protection for Excel file. You can set a file to only open when a password is provided, and you can set a file to only be changeable with a password provided. It sounds like you probably have both. Probably when you run xlswrite1, an invisible password prompt pops up. Check that this is the case by making Excel visible before writing. (Also, even if you want things running invisibly in the future, it's best to validate your code with Excel visible so you can see what's going on.) > > If it turns out you do need a second password, then your open call needs to look like this: > > eF = eW.Open([pn fn],[],false,[],passwd,passwd2); > > If that doesn't work, post again and we can try something else. Alright, For some reason when use this code to open the file that I actually want to do work in, it works fine. I also was able to get xlswrite to work as well. However when I try this on a sample file that has a password, it still prompts me for my password. This is not a big deal but it's a strange occurance. The only passwords that are on my files are to open to modify. One other question I have is how to get it to close and save when I'm done doing what I need to with the file. I know that Excels close function goes: Wkb("SomeWorkbook").close True That saves and closes it but how would that work in Matlab? Thanks again
First
|
Prev
|
Pages: 1 2 Prev: relational operator tolerences Next: How to align two time series fast? |