Consulting

Results 1 to 5 of 5

Thread: VBA Code to know the date of creating a new worksheet

  1. #1

    VBA Code to know the date of creating a new worksheet

    Hi everybody
    I have a strange request!!
    Is there a code to know the date when a worksheet is created??

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    This should record the creation in Sheet 3. It assumes 3 original sheets. Place in ThisWorkbook module
    [VBA]
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    If Right(Sh.CodeName, Len(Sh.CodeName) - 5) > 3 Then
    Sheet3.Cells(Rows.Count, 1).End(xlUp)(2) = Sh.CodeName
    Sheet3.Cells(Rows.Count, 2).End(xlUp)(2) = Now
    End If
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Thanks a lot Mr. mdmackillop
    I want to record the name of the sheet not the code name...
    Another thing ::what about existing worksheet , is there any way to record when they were created??

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I want to record the name of the sheet not the code name...
    I'm sure you can work that out for yourself.
    Another thing ::what about existing worksheet , is there any way to record when they were created??
    You could save in the "log" when the workbook was created. I know of no way to retrospectively obtain sheeet creation data.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    You need to use the workbook event Workbook_Newsheet, put this in the ThisWorkbook code module as a demo, add/insert a new sheet and you get a message, you should then be able to adapt it
    [VBA]Private Sub Workbook_NewSheet(ByVal Sh As Object)
    MsgBox Sh.Name & " was created " & Now
    End Sub[/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

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