View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Nigel[_2_] Nigel[_2_] is offline
external usenet poster
 
Posts: 735
Default Protect a Worksheet

Record your query and post the code here.

--

Regards,
Nigel




"Otter" wrote in message
...
Thanks Nigel that got me closer but now I get an error

Run-time error '438'

Object doesn't support this property or method

I have the "enable background refresh" box checked. I also tried it
unchecked and got the same thing. When I click the Debug button it takes
me
to the .QueryTableRefresh statement

Here is the code:

For Each wsSheet In Worksheets
wsSheet.Unprotect PWORD
Next wsSheet

With Sheets("Sales Basis").Range("G9")
.QueryTableRefresh BackgroundQuery:=False
End With

With Sheets("Sales Basis").Range("I9")
.QueryTableRefresh BackgroundQuery:=False
End With


For Each wsSheet In Worksheets
wsSheet.Protect PWORD
Next wsSheet



"Otter" wrote:

I have a worksheet that has a parameter query that was set up through the
Import External Data option. It is set to refresh on open and it errors
out
if I protect the worksheet and save it. I have tried protecting the
worksheet
with code but can't seem to find the correct place to put the code. I
tried
it in "This Workbook" but it protects it before the query runs and does
the
update. I have put the protect in the begining of the worksheet that I
want
to protect but it does not protect it. Any ideas?