Disable sheet and other macros while do loop is waiting for macro button response

txgent72

New Member
Joined
Mar 13, 2018
Messages
1
Hello, I am, not sure if my situation has been addressed before.
Here is my issue:
In excel, I have made a board game.
I have a PLAY button in P9 among other buttons (macros) ALSO in column P, which I want unavailable while the game is waiting for the player.

The player must decide to press which one of two gameplay 'yes/no' buttons (macros) in either e12:f12 or m12:n12.
If they press the play button, or type anything anywhere, errors will come up.

I am stumped as to how to make this work.
I attempted to lock the entire sheet with the exception of those needed ranges was:



ActiveSheet.Protect
Range("E12:F12").Locked = False
Range("M12:N12").Locked = False
DO
If Range("Action") > 0 Then
Exit Do
End If
DoEvents
Loop

When testing, I receive an error that it is unable to do the specified action to the specified cells.

I have successfully made a msgbox with yes or no that does exactly what I need. The rest of the game is blocked out by a spinning cursor while the msgbox is up waiting for an answer. But ultimately I don't want a message box in the final game. Just on screen buttons and the ability to block other buttons when appropriate to prevent errors that happen if they are pressed at the wrong times.

Fixing this issue is pretty much the last step before I compile the game to standalone EXE.

Thanks in advance!
Chris
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,776
Hi Chris and Welcome to the Board. You can change the colour of your buttons and don't let them do anything unless there the right colour (ie. button red then nothing happens when selected; button green then button acts normal). Here's some code to ponder. U can run this code while your waiting for the player to play. It doesn't have to have the message, the basic idea is to set a timer and check if anything has happened. HTH. Dave
Code:
Sub test()
'wait for player action
Before:
WaitTime
'eg. player action is to enter 1 in A1
If [sheet1!A1] = 1 Then
Exit Sub
Else
Set WsShell = CreateObject("WScript.Shell")
intText = WsShell.Popup("IT'S YOUR TURN!", 2, "HURRY UP!")
Set WsShell = Nothing
GoTo Before
End If
End Sub

Function WaitTime()
Dim PauseTime, Start
    PauseTime = 5    ' Set duration.
    Start = Timer    ' Set start time.
    Do While Timer < Start + PauseTime
        DoEvents    ' Yield to other processes.
    Loop
End Function
ps. please use code tags. Also this might give U some ideas...
https://www.mrexcel.com/forum/excel-questions/147166-take-tictactoe-test.html?highlight=tictactoe
 

Watch MrExcel Video

Forum statistics

Threads
1,129,577
Messages
5,637,190
Members
416,960
Latest member
Carbon1198

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top