Auto close message box after 1 minute

ste33uka

Active Member
Joined
Jan 31, 2020
Messages
471
Office Version
  1. 365
Platform
  1. Windows
Hi i use the following code for a message box, is there anyway it would auto close message box on 1 minute if i have not clicked before then?

VBA Code:
Private Sub Worksheet_Message()
Dim Msg As Long
    Dim myRange As Range
    Set myRange = Sheet85.Range("BD1:BD999")
    Dim cell As Range
    For Each cell In myRange
        Evaluate (cell)
        If StrComp(cell, "Yes", vbTextCompare) = 0 Then
        Cells(cell.Row, "BA") = 999999
        AppActivate Application.Caption
            Msg = MsgBox("" & vbCrLf & " " & Range("BG" & cell.Row).Value & vbCrLf & Range("BP" & cell.Row).Value & vbCrLf & Range("BQ" & cell.Row) & Range("BR" & cell.Row).Value, vbExclamation)
        End If
    Next
        Set myRange = Sheet85.Range("BE1:BE999")

    For Each cell In myRange
        Evaluate (cell)
        If StrComp(cell, "Yes", vbTextCompare) = 0 Then
        Cells(cell.Row, "BC") = 999999
        AppActivate Application.Caption
            Msg = MsgBox("" & vbCrLf & " " & Range("BG" & cell.Row).Value & vbCrLf & Range("BP" & cell.Row).Value & vbCrLf & Range("BQ" & cell.Row) & Range("BR" & cell.Row).Value, vbExclamation)
           
        End If
    Next                 
    End Sub
 
Last edited:

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try:

VBA Code:
    CreateObject("WScript.Shell").PopUp "Your Message goes Here", 60, "Title", 48


More information here:



I have a link somewhere that shows a message box that has a countdown timer in it that shows how long before it will close itself. Let me know if you want me to dig that out.
 
Upvote 0
Not with a MsgBox. You have to create your own UserForm. I can think of two approaches:

1. Make the form modeless. Upon activation, in the Sub that calls .Show, start a loop with DoEvents that exits after 1 minute elapses and closes the form (or does nothing if you click--click what, I don't know, you didn't say).

2. Upon activation set a timer using OnTime that will call a Sub to close the form. I am not sure if this requires a modeless form.

Edit: You will probably find the previous post meets your needs and is easier.
 
Upvote 0
FWIW, the Shell.Popup method is notoriously unreliable in VBA.
 
Upvote 0
The link to the code with the countdown timer is post 4 in this thread:


I haven't tested it, but maybe it's more reliable.
 
Upvote 0
Try:

VBA Code:
    CreateObject("WScript.Shell").PopUp "Your Message goes Here", 60, "Title", 48


More information here:



I have a link somewhere that shows a message box that has a countdown timer in it that shows how long before it will close itself. Let me know if you want me to dig that out.
Hey thanks for suggestion, how could i put the following message in ? i keep getting compile error

Msg = MsgBox("" & vbCrLf & " " & Range("BG" & cell.Row).Value & vbCrLf & Range("BP" & cell.Row).Value & vbCrLf & Range("BQ" & cell.Row) & Range("BR" & cell.Row).Value, vbExclamation)
 
Upvote 0
I do not get a compile error on this if I declare cell as a variable. What is the entire sub where you are using this? Is cell declared? Are you using Option Explicit?
 
Upvote 0
VBA Code:
        Private Sub Worksheet_Message()
Dim Msg As Long
Dim myRange As Range
Set myRange = Sheet85.Range("BD1:BD999")
Dim cell As Range
For Each cell In myRange
Evaluate (cell)
If StrComp(cell, "Yes", vbTextCompare) = 0 Then
Cells(cell.Row, "BA") = 999999
AppActivate Application.Caption
CreateObject("WScript.Shell").PopUp "Your Message goes Here", 60, "Title", 48
End If
Next
Set myRange = Sheet85.Range("BE1:BE999")

For Each cell In myRange
Evaluate (cell)
If StrComp(cell, "Yes", vbTextCompare) = 0 Then
Cells(cell.Row, "BC") = 999999
AppActivate Application.Caption
CreateObject("WScript.Shell").PopUp "Your Message goes Here", 60, "Title", 48
           
End If
Next
End Sub

This is sub i am using
I would like the message to say
("" & vbCrLf & " " & Range("BG" & cell.Row).Value & vbCrLf & Range("BP" & cell.Row).Value & vbCrLf & Range("BQ" & cell.Row) & Range("BR" & cell.Row).Value, vbExclamation)
 
Upvote 0
When you call MsgBox you are using the vbExclamation as the optional second argument. You can't include that in the PopUp call. See code below.

Also, why are you starting the message with vbCrLf?

Also, what do you expect this line of code to do:
VBA Code:
Evaluate (cell)
It is a call to a function but you are not assigning the result to anything. So this line of code doesn't do anything.

StrComp here seems like overkill. It works but I would just use
VBA Code:
If cell.Value = "Yes"

Also, indentation would help readability.

VBA Code:
Private Sub Worksheet_Message()
  
   Dim msg As Long
   Dim myRange As Range
   Set myRange = Sheet85.Range("BD1:BD999")
   Dim cell As Range
   
   For Each cell In myRange
      Evaluate (cell) ' ??????
      If StrComp(cell, "Yes", vbTextCompare) = 0 Then
         Cells(cell.Row, "BA") = 999999
         AppActivate Application.Caption
         CreateObject("WScript.Shell").PopUp vbCrLf & " " & Range("BG" & cell.Row).Value & vbCrLf & Range("BP" & cell.Row).Value & vbCrLf & Range("BQ" & cell.Row) & Range("BR" & cell.Row).Value, 60, "Title", 48
      End If
   Next cell
   
   Set myRange = Sheet85.Range("BE1:BE999")
   
   For Each cell In myRange
      Evaluate (cell)
      If StrComp(cell, "Yes", vbTextCompare) = 0 Then
         Cells(cell.Row, "BC") = 999999
         AppActivate Application.Caption
         CreateObject("WScript.Shell").PopUp vbCrLf & " " & Range("BG" & cell.Row).Value & vbCrLf & Range("BP" & cell.Row).Value & vbCrLf & Range("BQ" & cell.Row) & Range("BR" & cell.Row).Value, 60, "Title", 48
      End If
   Next cell
   
End Sub
 
Upvote 0
When you call MsgBox you are using the vbExclamation as the optional second argument. You can't include that in the PopUp call. See code below.

Also, why are you starting the message with vbCrLf?

Also, what do you expect this line of code to do:
VBA Code:
Evaluate (cell)
It is a call to a function but you are not assigning the result to anything. So this line of code doesn't do anything.

StrComp here seems like overkill. It works but I would just use
VBA Code:
If cell.Value = "Yes"

Also, indentation would help readability.

VBA Code:
Private Sub Worksheet_Message()

   Dim msg As Long
   Dim myRange As Range
   Set myRange = Sheet85.Range("BD1:BD999")
   Dim cell As Range
 
   For Each cell In myRange
      Evaluate (cell) ' ??????
      If StrComp(cell, "Yes", vbTextCompare) = 0 Then
         Cells(cell.Row, "BA") = 999999
         AppActivate Application.Caption
         CreateObject("WScript.Shell").PopUp vbCrLf & " " & Range("BG" & cell.Row).Value & vbCrLf & Range("BP" & cell.Row).Value & vbCrLf & Range("BQ" & cell.Row) & Range("BR" & cell.Row).Value, 60, "Title", 48
      End If
   Next cell
 
   Set myRange = Sheet85.Range("BE1:BE999")
 
   For Each cell In myRange
      Evaluate (cell)
      If StrComp(cell, "Yes", vbTextCompare) = 0 Then
         Cells(cell.Row, "BC") = 999999
         AppActivate Application.Caption
         CreateObject("WScript.Shell").PopUp vbCrLf & " " & Range("BG" & cell.Row).Value & vbCrLf & Range("BP" & cell.Row).Value & vbCrLf & Range("BQ" & cell.Row) & Range("BR" & cell.Row).Value, 60, "Title", 48
      End If
   Next cell
 
End Sub
im still learning code, half of what you said i dont understand
so i can delete "Evaluate (cell)"
and use " If cell.Value = "Yes"

i tried the code you you added, but it didnt auto close message
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

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
Back
Top