Excel Code : Editing for specific time period






This code for Workbook_Open

    Private Sub Workbook_Open()

    Call testTime

    End Sub


this code for Module

Sub macro_timer()

'Tells Excel when to next run the macro.

Application.OnTime Now + TimeValue("00:00:01"), "testTime"

End Sub

Sub testTime()

Dim datntime As String

Dim timee() As String

datntime = Now

timee = Split(datntime, " ")

If timee(1) > "10:00:00" And timee(1) < "11:00:00" Then

Application.ActiveWorkbook.Activate

Else

MsgBox ("you can edit this sheet only from 10 am to 11 am.")

Application.ActiveWorkbook.Save

Application.Quit

End If

Call macro_timer

End Sub

Comments

Popular Posts