Code for Last Modified Stamp for an Excel Spreadsheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leighaeroe
    New Member
    • Jan 2014
    • 1

    Code for Last Modified Stamp for an Excel Spreadsheet

    I need to stamp a spreadsheet with the last modified date and time.Can someone help with the code that would put that in cell B2 of an Excel spreadsheet?
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    This is for VB.NET. Hope it helps. You will also need to add a reference to your project for Microsoft Office Interop Excel and Import Microsoft.Offic e.Interop

    Code:
    'insert the path of your file here
            Dim filepath = "c:\Book1.xlsx"
    
            If My.Computer.FileSystem.FileExists(filepath) Then
                Dim excelApp As New Excel.Application
                Dim workBook As Excel.Workbook = excelApp.Workbooks.Open(filepath)
                'Change "Sheet1" to the name of your worksheet
                Dim workSheet As Excel.Worksheet = CType(workBook.Worksheets("Sheet1"), Excel.Worksheet)
                Dim cellRange As Excel.Range = workSheet.Range("B2")
    
                cellRange.Value = File.GetLastWriteTime(filepath)
                workBook.Close(SaveChanges:=True)
                excelApp.Quit()
            End If

    Comment

    Working...