can i write code it should display the message before shutdown you need logout

tiger123

New Member
Joined
Jun 24, 2014
Messages
37
when trying to shut down the system
it should display the message before shutdown you need logout

then it should display an userform

after logout the system need to shutdown automatically it is possible to

Please help me how can i do it


Code:
Private Sub CommandButton1_Click()Dim irow As Long
Dim ws As Worksheet




Dim info
info = IsWorkBookopen("\\bms\Service log request\login details\workstation.xlsx")




'we open the workbook if it is closed
If info = False Then
Workbooks.Open ("\\bms\Service log request\login details\workstation.xlsx")
End If


 Set ws = Worksheets("Logout Time")


'Find first empty row in database
 irow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
 SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1






'Check for a Name number
If Trim(Me.txt1.Value) = "" Then
Me.lbl2.SetFocus
End If


'Copy the data to the database
ws.Cells(irow, 1).Value = Me.lbl1.Object
ws.Cells(irow, 2).Value = Me.lbl2.Object
ws.Cells(irow, 3).Value = Me.lbl3.Object
ws.Cells(irow, 4).Value = Me.lbl4.Object
ws.Cells(irow, 5).Value = Me.txt1.Value
ws.Cells(irow, 6).Value = Me.txt2.Value


 Me.lbl1.Caption = ""
 Me.lbl2.Caption = ""
 Me.lbl3.Caption = ""
 Me.lbl4.Caption = ""
 Me.txt1.Value = ""
 Me.txt2.Value = ""




 Me.txt1.SetFocus


Application.DisplayAlerts = False
Workbooks("workstation.xlsx").Save
Workbooks("workstation.xlsx").Close
Application.DisplayAlerts = True


MsgBox "You have Logged Out close the file"


Unload Logout


End Sub


Private Sub UserForm_Initialize()
Me.lbl1 = Application.username
Me.lbl3 = Date
Me.lbl4 = Time
Me.lbl2 = Environ$("computername")
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,054
Latest member
juliecooper255

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