So apparently no one else has run into this problem? Seems odd that Query.Refresh would not to allowed under UserInterFaceOnly. Can anyone else verify this?
Main Topics
Browse All TopicsI'm trying to set up a workbook to allow my macros to run while protection is on (without a password). I've got the following code in the private module of ThisWorkbook.
Private Sub Workbook_Open()
Dim wSheet As Worksheet
For Each wSheet In Worksheets
wSheet.Protect UserInterFaceOnly:=True
Next wSheet
End Sub
When I run my macros, The ones that have query.refresh get the runtime error saying the cell I am trying to change is protected. Does UserInterFaceOnly not apply to query refresh?
Is there some other setting or code I need to make this work? Does it matter if I have protection on or off in each worksheet? I'm using Excel 2003. My query pulls data from a csv file.
My macros run fine if I unprotect every sheet manually and don't use the UserInterFaceOnly, but I need to have the sheets protected. I would rather not use protect/unprotect in the macro because if the macro gets terminated then protection is not set.
Jeff
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: folderolPosted on 2009-07-10 at 15:32:36ID: 24828046
I can't get it to work either. Apparantly, there is too much going on with a refresh, column widths, formatting, sorts and filters, new rows inserted, and I tried disabling all of that and the query still won't run.
You need to use an On Error statement to protect the sheet if an error occurs in the macro.
Select allOpen in new window