password on a worksheet

  • Thread starter Thread starter merf
  • Start date Start date
M

merf

Hi,

I'am using Excel 2000 and win2000 prof

I copy the range("a1:f10") from one file into another file. On this last
file, there is only one worksheet which is protected by a password.
I trie to bypass this password, but mostly (not allways) an error occur
(err.number 1004 with description that "the method op pastespecial of the
class range is not succesfull.)

the error occur after this part of code

'------------------------------------

workbooks.open filename:"d:\file2.xls",updatelinks:=0 ,readonly:=false

ActiveSheet.Unprotect "password" ' this should uninstall the password
worksheets("sheet1").range("a1:f9").pastespecial
paste:=xlvalues,operation:=xlnone,skipBlanks:=false, transpose:=false

'Now the error 1004 occurs
ActiveSheet.Protect "password" ' to reinstall the password

'-------------------------

Very strange that sometimes the error does not occur and the code proceeds !
Quid ??

What's causes (mostly) this error ??

Thanks for your help, Merf
 
Hi
maybe the mixed use of Activesheet and worksheets("sheet1") causes this
error. Try

Dim wbk as workbook
Dim wks as worksheet
workbooks.open filename:"d:\file2.xls",updatelinks:=0 ,readonly:=false

set wbk = workbooks("file2.xls")
set wks = wbk.worksheets("sheet1")

wks.Unprotect "password" ' this should uninstall the password
wks.range("a1:f9").pastespecial
paste:=xlvalues,operation:=xlnone,skipBlanks:=false, transpose:=false

'Now the error 1004 occurs
wks.Protect "password"
 
Hi, Frank

i replace your code into mine, but the same error occurs.

thanx to your effort, merf
 
Back
Top