View Full Version : time and date in the excel cell
morteza2006
07-12-2013, 09:48 PM
Hello to all
How the Internet and the Web in time and date created an Excel cell?
http://www.time.ir/fa/home
Option Explicit
'Adjust to suit
Private Const TimeDisplaySheetName As String = "Sheet1"
Private Const DateCellAddress As String = "A1"
Private Const TimeCellAddress As String = "A2"
Private Sub Workbook_SheetActivate(ByVal Sht As Object)
'Shows date and time when correct sheet is activated
If Sht.Name = TimeDisplaySheetName Then Showtime
End Sub
Private Sub Showtime()
'Shows time only when correct sheet is active
'Constants used to show how Interval is calculated
Const DAYs As Long = 1
Const HRs As Long = 24
Const MINs As Long = 60
Const SECs As Long = 60
Dim PreviousTime As Long
Dim Interval As Long
'For 1 minute intervals, do not divide by SECs
Interval = (((DAYs / HRs) / MINs) / SECs)
Do 'Loop iterates continuously
If ActiveSheet.Name <> TimeDisplaySheetName Then Exit Sub
With Sheets(TimeDisplaySheetName)
'If sheet is activated while midnight occurs
If Now > PreviousTime + DAYs Then .Range(DateCellAddress) = Date
If Now > PreviousTime + Interval Then
.Range(TimeCellAddress) = Time
.Calculate 'Insure time for sheet to calculate
End If
DoEvents 'Allow time for other Excel processes
End With
Loop
End Sub
I would use:
Sub M_snb()
Sheets(1).Cells(10, 3) = Format(Now, "hh:mm:ss")
Application.StatusBar = DateAdd("s", 1, Now)
Application.OnTime CDate(Application.StatusBar), "sheet1.M_snb"
End Sub
Private Sub knop_start_Click()
M_snb
End Sub
Private Sub knop_stop_Click()
Application.OnTime CDate(Application.StatusBar), "sheet1.M_snb", , False
End Sub
morteza2006
07-13-2013, 09:53 PM
Dear friends
Thanks for your answer
But I want to get date and time from the Internet.
I am grateful to be able to help
Internet time is different?!?!?!? :bug:
morteza2006
07-14-2013, 03:08 AM
Internet time is different?!?!?!? :bug:
I want to get on the site
Is it possible??
http://www.time.ir/fa/home
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.