Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jan 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A user wants to have a number or date put into a workbook when someone saves the workbook. I poked around Google, and I found this...

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    ' code or call to routine here....

    End Sub

    As a test, my code was saving the date in a named range. I also stuck a messagebox in there to just see if was getting called, but no luck.
    It doesn't seem to be working. Does anyone know if it's possible to have a macro run when someone saves the workbook?

  2. #2
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes it is possible. This is an example of some code that I currently have in use.

    Code:
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    
    Dim hme As Worksheet
    
    Application.ScreenUpdating = False
    Call AdminWbUnlock(False)
    
        Set hme = Worksheets("Home")
        
        hme.Range("T3").Value = Now()
        hme.Range("A1").Select
    
    Call AdminWbLockUp(False)
    Application.ScreenUpdating = True
    
    End Sub

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Quote Originally Posted by projecktzero View Post
    It doesn't seem to be working. Does anyone know if it's possible to have a macro run when someone saves the workbook?
    Note that to work, the code has to be in the workbook's ThisWorkbook private module.

    Gary

Posting Permissions

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