Consulting

Results 1 to 6 of 6

Thread: time and date in the excel cell

  1. #1

    Question time and date in the excel cell

    Hello to all
    How the Internet and the Web in time and date created an Excel cell?
    http://www.time.ir/fa/home
    Attached Images Attached Images
    • File Type: jpg s.jpg (84.0 KB, 5 views)

  2. #2
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    [VBA]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
    [/VBA]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    I would use:

    [vba]
    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

    [/vba]
    Attached Files Attached Files

  4. #4
    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

  5. #5
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Internet time is different?!?!?!?
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6

    SamT

    Quote Originally Posted by SamT
    Internet time is different?!?!?!?
    I want to get on the site
    Is it possible??

    http://www.time.ir/fa/home

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •