MsgBox not working and Reopen option

eli_m

Board Regular
Joined
Jun 2, 2022
Messages
129
Office Version
  1. 365
Platform
  1. Windows
Hi All,

For some reason this code works great but the MsgBox command doesn't work anymore:
VBA Code:
Option Explicit
Public DownTime As Double

Sub StartTimer()
    DownTime = Now + TimeSerial(0, 30, 0)
    Application.OnTime DownTime, "ShutDown"
End Sub

Sub StopTimer()
    On Error Resume Next
    Application.OnTime DownTime, "ShutDown", , False
 End Sub

Sub ShutDown()
    With ThisWorkbook
        Application.DisplayAlerts = False
        .Close Savechanges:=True
        Application.DisplayAlerts = True
    End With
        MsgBox "Timed out after 30 minutes - Your work has been saved and closed"
End Sub


Also is there a way to have a "Reopen" button so it reopens the Workbook it just closed as well as a "OK" button?

Thanks in advance!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
It looks like you've closed the workbook so all code stops at .Close.
VBA Code:
Sub ShutDown()
    With ThisWorkbook
        Application.DisplayAlerts = False
Ans = MsgBox("Would you like to continue working?", vbYesNo, "Done Working?")
           If Ans = vbYes Then
                     Application.Workbooks.Open("YourFileLocation")
           End If
        .Close Savechanges:=True
        Application.DisplayAlerts = True
    End With
       
End Sub
 
Upvote 0
It looks like you've closed the workbook so all code stops at .Close.
VBA Code:
Sub ShutDown()
    With ThisWorkbook
        Application.DisplayAlerts = False
Ans = MsgBox("Would you like to continue working?", vbYesNo, "Done Working?")
           If Ans = vbYes Then
                     Application.Workbooks.Open("YourFileLocation")
           End If
        .Close Savechanges:=True
        Application.DisplayAlerts = True
    End With
      
End Sub

Ah I see. I'm getting this error with your code:
1676945817291.png


Is it because my workbook link is a sharepoint URL?
 

Attachments

  • 1676945670245.png
    1676945670245.png
    22.5 KB · Views: 2
Upvote 0
Are you using the statement Option Explicit? If so, DIM Ans as Variant
 
Upvote 0
Are you using the statement Option Explicit?
I am - Full code:

VBA Code:
Option Explicit
Public DownTime As Double

Sub StartTimer()
    DownTime = Now + TimeSerial(0, 30, 0)
    Application.OnTime DownTime, "ShutDown"
End Sub

Sub StopTimer()
    On Error Resume Next
    Application.OnTime DownTime, "ShutDown", , False
 End Sub
Sub ShutDown()
    With ThisWorkbook
        Application.DisplayAlerts = False
Ans = MsgBox("Would you like to continue working?", vbYesNo, "Done Working?")
           If Ans = vbYes Then
                     Application.Workbooks.Open ("https://my.sharepoint.com/:x:/r/personal")
           End If
        .Close Savechanges:=True
        Application.DisplayAlerts = True
    End With
      
End Sub
 
Upvote 0
I am - Full code:

VBA Code:
Option Explicit
Public DownTime As Double

Sub StartTimer()
    DownTime = Now + TimeSerial(0, 30, 0)
    Application.OnTime DownTime, "ShutDown"
End Sub

Sub StopTimer()
    On Error Resume Next
    Application.OnTime DownTime, "ShutDown", , False
 End Sub
Sub ShutDown()
    With ThisWorkbook
        Application.DisplayAlerts = False
Ans = MsgBox("Would you like to continue working?", vbYesNo, "Done Working?")
           If Ans = vbYes Then
                     Application.Workbooks.Open ("https://my.sharepoint.com/:x:/r/personal")
           End If
        .Close Savechanges:=True
        Application.DisplayAlerts = True
    End With
     
End Sub
Are you using the statement Option Explicit? If so, DIM Ans as Variant
 
Upvote 0
Are you using the statement Option Explicit? If so, DIM Ans as Variant
Sorry that went over my head - what do you mean? I've posted the full code (pressed enter too quickly before)
 
Upvote 0
VBA Code:
Option Explicit
Public DownTime As Double
Dim Ans as Variant
Sub StartTimer()
    DownTime = Now + TimeSerial(0, 30, 0)
    Application.OnTime DownTime, "ShutDown"
End Sub

Sub StopTimer()
    On Error Resume Next
    Application.OnTime DownTime, "ShutDown", , False
 End Sub
Sub ShutDown()
    With ThisWorkbook
        Application.DisplayAlerts = False
Ans = MsgBox("Would you like to continue working?", vbYesNo, "Done Working?")
           If Ans = vbYes Then
                     Application.Workbooks.Open ("https://my.sharepoint.com/:x:/r/personal")
           End If
        .Close Savechanges:=True
        Application.DisplayAlerts = True
    End With
       
End Sub
 
Upvote 0
Solution
VBA Code:
Option Explicit
Public DownTime As Double
Dim Ans as Variant
Sub StartTimer()
    DownTime = Now + TimeSerial(0, 30, 0)
    Application.OnTime DownTime, "ShutDown"
End Sub

Sub StopTimer()
    On Error Resume Next
    Application.OnTime DownTime, "ShutDown", , False
 End Sub
Sub ShutDown()
    With ThisWorkbook
        Application.DisplayAlerts = False
Ans = MsgBox("Would you like to continue working?", vbYesNo, "Done Working?")
           If Ans = vbYes Then
                     Application.Workbooks.Open ("https://my.sharepoint.com/:x:/r/personal")
           End If
        .Close Savechanges:=True
        Application.DisplayAlerts = True
    End With
      
End Sub
The message box worked great! but it didn't allow me to reopen my work book .Is it because it's a link?
 
Upvote 0
And to answer your other question. I have had problems saving to Cloud locations. I had to use the local file that syncs.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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