Solved

UserInterFaceOnly won't allow query to refresh

Posted on 2009-07-10
6
512 Views
Last Modified: 2013-11-25
I'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
0
Comment
Question by:jfwsmith
  • 4
  • 2
6 Comments
 
LVL 19

Expert Comment

by:folderol
ID: 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.
Sub Macro3()

'

    ActiveSheet.Unprotect

    On Error GoTo rollback

    ActiveSheet.Cells(1, 1).Value = "Older"  ' overwritten if refresh succeeds, cheap debug flag

    ActiveSheet.QueryTables(1).Refresh

    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, userinterfaceonly:=True

    Exit Sub

rollback:

    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, userinterfaceonly:=True

    MsgBox "protected again"

End Sub

Open in new window

0
 

Author Comment

by:jfwsmith
ID: 24881420
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?
0
 
LVL 19

Accepted Solution

by:
folderol earned 500 total points
ID: 24881663
Consider it verified.  Poor choice of words I guess, but I only meant to imply I hadn't used a rigourous QA testing process.  A google search turned up only articles that agreed that unprotect / query.refresh / protect is the only option.

Tom.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 19

Expert Comment

by:folderol
ID: 24881951
I suppose the B grade was intended as a sign of protest to Microsoft, for omitting this obviously useful feature :)
I'll gladly be the messenger, even if it ends up getting me shot! lol
0
 

Author Comment

by:jfwsmith
ID: 24882562
Sorry, I'm not familiar with what the grading is all about.  No reflection on you personally, the answer just didn't tell me much that I didn't already know... (I already googled it myself, my reason for posting here was to seek further clarification).  Thank you for your response and efforts.
Jeff
0
 
LVL 19

Expert Comment

by:folderol
ID: 24882671
No offense was taken, so think nothing of it, really.  Maybe it was a bit snarky, but I couldn't resist the joke.  Many a time, posters grade on what they hoped to hear, rather than the response's accuracy.  Funny but only human I guess, its very widespread.  I apologize if I seemed ungrateful.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now