+ Reply to Thread
Results 1 to 9 of 9

strange protected sheet issue, refresh query tables

  1. #1
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    strange protected sheet issue, refresh query tables

    I'm having a strange problem when I attempt to refresh some query tables on a protected sheet.

    Prior to the refresh, I have included a line to unprotect the sheet (see below) and after the refresh, I protect it again.

    When I step through this code, one line at a time using F8, it works perfectly. But when I run the code in the normal way, I get a pop-up telling me "The cell I'm trying to change is on a protected sheet."

    Anyone encountered something like this before? Again, it works when I step through the code - but only then.


    Please Login or Register  to view this content.
    Last edited by GeneralDisarray; 10-01-2014 at 09:22 AM.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: strange protected sheet issue, refresh query tables

    Try protecting the sheet only for the user interface, so that instructions run via VBA act as if the sheet is unprotected:
    Please Login or Register  to view this content.
    With the sheet protected this way, you don't need the 'unprotect' command at the start of your routine. Note this protection needs applied when the workbook is opened, so I'd suggest triggering this protection line in the workbook_open event.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: strange protected sheet issue, refresh query tables

    Please Login or Register  to view this content.

    Tried, that still doesn't seem to work.

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: strange protected sheet issue, refresh query tables

    Try enabling background refresh on your data queries.

  5. #5
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: strange protected sheet issue, refresh query tables

    That was already done.


    It's really strange, but I've checked it and it definitely is running the refresh as desired IF i step-through it. As soon as I run it normally, it get a popup for both refresh statements - and the refresh doesn't happen either.

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: strange protected sheet issue, refresh query tables

    It sounds like the sheet protection is happening before the data refresh is finished - but protecting the sheet userinterface only should prevent that from being a problem...

    I'm out of ideas, I'm afraid.

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: strange protected sheet issue, refresh query tables

    I think you must disable background refresh.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  8. #8
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: strange protected sheet issue, refresh query tables

    AH HA!


    I tried setting to false - but did it in the wrong place. You DON'T disable it in the user interface - you do it in the code. I dressed the macro up a bit more while I was at it, but the key was passing false to the "BackgroundQuery" parameter. Edit: I think unchecking the box should have worked in the user interface also - but only if I left the parameter out of the code. Doing it in the code is a little more fool proof.

    Setting FALSE kept the worksheet unlocked until the refresh was complete.

    Your comment and the default F1 help saved the day :D

    Description of the BackgroundRefresh Parameter: Used only with QueryTables that are based on the results of a SQL query. True to return control to the procedure as soon as a database connection is made and the query is submitted. The QueryTable is updated in the background. False to return control to the procedure only after all data has been fetched to the worksheet. If this argument isn't specified, the setting of the BackgroundQuery property determines the query mode.

    Please Login or Register  to view this content.
    Last edited by GeneralDisarray; 10-01-2014 at 09:39 AM. Reason: bad explanation

  9. #9
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: strange protected sheet issue, refresh query tables

    Glad you figured it out

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. refresh pivot tables while sheets are protected
    By LeeRichard in forum Excel Charting & Pivots
    Replies: 11
    Last Post: 08-02-2014, 04:24 AM
  2. VBA to refresh all pivot tables on all protected worksheets
    By ef67 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 03-19-2013, 04:39 PM
  3. Refresh query with a password protected workbook.
    By Joy C in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2011, 12:31 PM
  4. Query does not refresh if sheet protected
    By sumdumgai in forum Excel General
    Replies: 0
    Last Post: 09-17-2008, 12:10 PM
  5. [SOLVED] [SOLVED] While sheet is protected, allow cmdButton to refresh query.
    By mhng in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2006, 01:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1