Consulting

Results 1 to 3 of 3

Thread: Solved: Message Box On Open

  1. #1
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location

    Solved: Message Box On Open

    Can a message box pop up every 10th time the file is open?? 15th time?? I did the easy part, here is my code, I can't figure this out.

    [VBA]
    Private Sub Workbook_Open()
    MsgBox ("This File Was Created By John Smith. (Updated 4/24/2006)")
    End Sub
    [/VBA]

    How do you count the amount of times the file is opened?
    Thanks
    Gary

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    '-----------------------------------------------------------------
    Private Sub Workbook_Open()
    '-----------------------------------------------------------------
    Dim cOpen As Long

    cOpen = 0 ' in case it doesn't already exist
    On Error Resume Next
    cOpen = Evaluate(ThisWorkbook.Names("OpenCount").RefersTo)
    cOpen = cOpen + 1
    If cOpen = 10 Then
    MsgBox "10th time of opening"
    cOpen = 0
    End If
    ThisWorkbook.Names.Add Name:="OpenCount", RefersTo:="=" & cOpen

    End Sub
    [/vba]

    This is workbook event code.
    To input this code, right click on the Excel icon on the worksheet
    (or next to the File menu if you maximise your workbooks),
    select View Code from the menu, and paste the code

  3. #3
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location
    Thanks XLD works great. Please mark this one solved.
    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
  •