+ Reply to Thread
Results 1 to 9 of 9

Screen Refresh/Repaint in VBA

  1. #1
    Registered User
    Join Date
    10-27-2009
    Location
    Madrid, Spain
    MS-Off Ver
    Excel 2003
    Posts
    7

    Screen Refresh/Repaint in VBA

    I have inserted several command buttons on an Excel 2003 worksheet. Each button executes a separate VBA macro. I would like one of these macros to make one of the command buttons invisible. The target button (called "Update") will become visible again if the user modifies any data in the worksheet.

    Everything works fine, except that the target button remains visible - although inactive - after the code is executed. If I minimize the Excel application window and then maximize it again, the Update button vanishes, as it should. This suggests that the screen must be refreshed after the macro is executed in order to make the button invisible to the user.

    I have seen other posts related to this problem (http://www.excelforum.com/excel-prog...ml#post2188184), but I'm having difficulty implementing the solution myself.

    If I add the following line to my macro:

    Please Login or Register  to view this content.
    I get the following error box:
    Compiling error. Could not find the method or data member.
    It seems that the Repaint method is not available to me in Excel VBA. Have I misunderstood how to use this method? I'm not using a userform, but just working with command buttons directly in the Excel spreadsheet. Thanks in advance for any help.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Screen Refresh/Repaint in VBA

    Repaint does not work with worksheets. Setting Application.ScreenUpdating = True should cause a screen refresh. If you are using buttons from the Control Toolbox it might not work with those.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    10-27-2009
    Location
    Madrid, Spain
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Screen Refresh/Repaint in VBA

    You're right, Romperstomper. Adding

    Please Login or Register  to view this content.
    does not refresh the buttons from the Control Toolbox.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Screen Refresh/Repaint in VBA

    Unless you specifically need the added functionality of the ActiveX ones, I would always use controls from the Forms toolbar in worksheets instead. They are more stable.
    As a matter of interest, what code do you use to hide the buttons?

  5. #5
    Registered User
    Join Date
    10-27-2009
    Location
    Madrid, Spain
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Screen Refresh/Repaint in VBA

    My codes lines for making the "Update" button invisible:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Screen Refresh/Repaint in VBA

    Is that code in the click event for the same button, or for another button?

  7. #7
    Registered User
    Join Date
    10-27-2009
    Location
    Madrid, Spain
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Screen Refresh/Repaint in VBA

    It is in the click event for the same button. In other words, when the user clicks the Update button, a series of calculations are performed, the output is sent to another worksheet, and then the button goes invisible. The button becomes visible again if any data in the sheet is modified.
    So, by the presence or absence of the Update button, the user knows whether the calculations are updated or not.

  8. #8
    Registered User
    Join Date
    06-03-2013
    Location
    Johannesburg
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Screen Refresh/Repaint in VBA

    Hi Folks, try this it works for me on both Form and ActiveX controls:

    Application.EnableEvents=true

    ..... make your changes to the tools on the worksheet......

    DoEvents

  9. #9
    Registered User
    Join Date
    08-18-2015
    Location
    Wellington, New Zealand
    MS-Off Ver
    Professional Plus 2013
    Posts
    1

    Re: Screen Refresh/Repaint in VBA

    Hi all,

    I'm afraid I've not found any of the above methods mentioned work for ActiveX controls however for run-time customisation reasons I need to use ActiveX controls over a Form control. As a result I've been struggling with this for a while and the only solution I've found to work so far is to call the "Activate" method on the control which seems to include a repaint of the control (presumably because it adds the focus box to the control). The change of focus on the worksheet isn't a problem in my context, though I appreciate that's not the case for everyone. Anyway, hope this helps anyone else still struggling with this.

    The code I end up using therefore looks like:

    Please Login or Register  to view this content.
    Last edited by rcjcooke; 08-19-2015 at 12:29 AM. Reason: fix another typo!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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