close

I tried to sort a sheet via VBA and kept getting an error until I
figured it was the protection stopping things. How can I turn off
protection, sort, then turn on protection again?

I looked in help and found ActiveWorkbook.Unprotect (quot;passwordquot;) but it
doesn't work. Any pointers in the right direction much appreciated.

TIA,
R.

Try

ActiveSheet.Unprotect password:=quot;whateverquot;
' do your sort
ActiveSheet.Protect password:=quot;whateverquot;--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.comquot;Mike Echoquot; gt; wrote in message u...
gt;I tried to sort a sheet via VBA and kept getting an error until
gt;I
gt; figured it was the protection stopping things. How can I turn
gt; off
gt; protection, sort, then turn on protection again?
gt;
gt; I looked in help and found ActiveWorkbook.Unprotect
gt; (quot;passwordquot;) but it
gt; doesn't work. Any pointers in the right direction much
gt; appreciated.
gt;
gt; TIA,
gt; R.
In article gt;,
says...

gt; ActiveSheet.Unprotect password:=quot;whateverquot;
gt; ' do your sort
gt; ActiveSheet.Protect password:=quot;whateverquot;

I found this code (on your website, no less :-)) and tried it but I
still get the same error message. If I unprotect the sheet the sort code
is fine. As soon as I protect the sheet things all go pear-shaped. This
has me baffled and I cannot imagine what may be causing it.

I recorded a macro to do the quot;unprotect then protectquot; thing and viewed
the code and even though I had entered a password, the macro didn't show
this. It simply showed quot;ActiveSheet Unprotectquot; etc.

I'll play more. It is probably something obviously stupid. That's
normally what happens with me. ;-)

Thanks for the reply, Chip.

*** Just had a thought. Could it be because I tend to put re-usable subs
in a module then quot;Callquot; them from the worksheet object as opposed to
having the same sub on different worksheets? My file is at work so I'll
have a look tomorrow.

全站熱搜
創作者介紹
創作者 software 的頭像
software

software

software 發表在 痞客邦 留言(0) 人氣()