+ Reply to Thread
Results 1 to 22 of 22

Macro cancelling pending refresh problem

  1. #1
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Question Macro cancelling pending refresh problem

    Morning,

    I have a macro which:

    Opens up a workbook
    Presses refresh all
    Waits 10 seconds
    Selects 1 cell
    Saves the workbook
    Closes the workbook

    At some point in this process a dialog box comes up saying 'this action will cancel a pending refresh command' or words like that. Does anyone know how I can bypass this? It interrupts the macro.

    Thanks

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro cancelling pending refresh problem

    Hi,

    Does

    Please Login or Register  to view this content.
    as the first line of the procedure help?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Macro cancelling pending refresh problem

    You can try:

    Please Login or Register  to view this content.
    at the start of your code, then set to TRUE again at the end.

  4. #4
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro cancelling pending refresh problem

    Yes and no - it stops the message appearing but it still stops the rest of the macro from working. All it does is open the book, wait 10 seconds, select the cell then close it - it doesn't refresh it

  5. #5
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Macro cancelling pending refresh problem

    Hmm. What do you mean by 'refresh all'? Can you provide your code?

  6. #6
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro cancelling pending refresh problem

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Macro cancelling pending refresh problem

    Hmm. Looks alright, have you tryed stepping through the macro (F8 in the VBA editor) to see exactly where the message box is called (so remove the displayalerts code for now). That should give an idea as to what is interrupting the refresh.

  8. #8
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro cancelling pending refresh problem

    The msg box says "this action will cancel a pending Refresh Data command. Continue?" It has a cancel or OK option..

  9. #9
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Macro cancelling pending refresh problem

    If you stepped through the code, which line of code is highlighted yellow when this box ocurred?

  10. #10
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro cancelling pending refresh problem

    It doesn't happen when I step through it - so it must be something to do with the timing of the macro?

  11. #11
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Macro cancelling pending refresh problem

    Now that does sound odd. It's very, very clunky (and I hate myself for suggesting it!) but try increasing your 'wait' time to 15 seconds.

    If you're not too fussed about good coding practice and that works: great!

    If you are fussed and it works, then it at least nails down a potential source of the issue.

  12. #12
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro cancelling pending refresh problem

    Even on 15 seconds it still brings up the msg box. I'm fairly sure that it's something to do with the saving and closing of the workbook because if I take those two lines out it works perfectly. I'm going to be running this for 26 sheets though - so closing them manually afterwards is going to be quite laborious.....

  13. #13
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Macro cancelling pending refresh problem

    Try the following instead of your save/close. If your filename includes the extension, you can delete the & ".xls" (including speech marks) from the below.

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro cancelling pending refresh problem

    Will that save it?

  15. #15
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Macro cancelling pending refresh problem

    Yes, the TRUE is a command to save.

  16. #16
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro cancelling pending refresh problem

    Sorry do I actually need to enter the filename or just have FileName?

  17. #17
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Macro cancelling pending refresh problem

    I'm assuming you have 'filename' defined somewhere in order to open your file initially, use the same string to represent both.

  18. #18
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro cancelling pending refresh problem

    Hi,

    It sounds like you may have a data connection which is getting data from another source and that the timer is not giving it enough time to complete.
    Have you tried inserting a DoEvents after the Open Filename instruction?

  19. #19
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro cancelling pending refresh problem

    again it "works" but doesn't actually refresh the sheet..

  20. #20
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro cancelling pending refresh problem

    Richard - how would i put that in?

  21. #21
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro cancelling pending refresh problem

    First of all is there a Data Connection involved here?
    If there is, is the Background Query Refresh property ticked or not?

    The Do Events would probably be better after the .RefreshAll instruction, but first try commenting out the Wait instruction and allowing the query to run its course

    If that doesn't help try setting the wait time longer than 3 seconds. Do you know typically how long the data connection takes to run - assuming a data connection is present of course. If so you should set the wait time to at least that plus an extra margin.

  22. #22
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro cancelling pending refresh problem

    Yes there is a data connection - it's a query
    Yes the background refresh is ticked

    The query only takes about 1 or 2 seconds to refresh - it is a quick one.

    I have tried the wait at 15 seconds and the same thing happens..

+ 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. Macro edit to fix refresh problem
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-06-2014, 05:07 AM
  2. Cancelling OnTime events problem
    By JamesFletcher in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-13-2013, 03:38 AM
  3. Problem with refresh all - "This action will cancel a pending.."
    By rajeshksv37 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-09-2009, 12:05 PM
  4. Action will Cancel Pending Refresh Command
    By mdk5008 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2009, 12:33 PM
  5. [SOLVED] Cancelling a macro
    By Naive in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2005, 12:06 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