Retrieving data from another workbook (path?)

  • Thread starter Thread starter Big Chris
  • Start date Start date
B

Big Chris

Happy Saturday!

Please can anyone help. I've done the searches and can't find an
clues...I think maybe my question is just too simple....

I am getting a macro to password protect a worksheet with a password i
a specif cell in another open workbook.

The code:

ActiveSheet.Protect Password:=Sheets("sheet1").Range("a1").Value

....works perfectly for inputting the password from within the sam
workbook, but I'm blowed if I can find the code for referencing
specific cell in a different open workbook.
Logic tells me it should be

ActiveSheet.Protec
Password:=workbook("book9").Sheets("sheet1").Range("a1").Value

...but that doesn't work.

Any help would be very much appreciated.

Have a good weekend
 
Doh!

Sorry to waste your time....I just realised that I simply missed an 'S
off of workbookS. It works fine now.

I'm a newbie and the syntax is hard to get my head aroun
sometimes....I'll get there!!

Many thanks
 
Chris,

Do you get a subscript out of range error? This suggests it cannot find that
workbook.

If this is the case, there is an unfortunate situation here. When you refer
to a new workbook, on that hasn't been saved yet, you use the 'book9'
syntax, but when you are dealing with a workbook that has been previously
saved, you need the .xls file extension, 'book9.xls'

The best way is to set an object variable to the workbook up-front, and use
that. Much more flexible.

Set oWB9 = Workbooks("book9.xls")
ActiveSheet.ProtectPassword:=oWb9.Sheets("sheet1").Range("a1").Value


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top