+ Reply to Thread
Results 1 to 3 of 3

Workbook Open Event

Hybrid View

  1. #1
    Registered User
    Join Date
    12-05-2013
    Location
    Utah
    MS-Off Ver
    Excel 2013
    Posts
    31

    Workbook Open Event

    I have a workbook with three sheets. I am wondering if is is possible to run an on open event that performs functions on Sheet1?

    For example, the following looks through the D column and if the date in that column matches today's date a toggle button is displayed. I want the toggle button to be hidden by default when the workbook is opened and then unhidden if the criterion is matched.


    Sub Revisit()
    
    Dim xdate As Date
    Dim lastrow As Long
    Dim c As Range
    Dim Rng As Range
    Dim count As Long
    count = 0
    lastrow = Range("A" & Rows.count).End(xlUp).Row
    
    Set Rng = Range("D2:D" & lastrow)
    For Each c In Rng
        xdate = c.Value
           If Month(Date) = Month(xdate) And Year(Date) = Year(xdate) Then
          
          count = count + 1
           Else
         
           End If
       Next
    
    If count > 0 Then
    
    ToggleButton1.Visible = True
    ToggleButton1.BackColor = RGB(255, 0, 0)
    ToggleButton1.Caption = "Re-Visit"
    ToggleButton1.Font.Bold = True
    ToggleButton1.Font.Size = 18
    Else
    ToggleButton1.Visible = False
    End If
    
    
    End Sub
    How do I go about setting this up to run on workbook open?

  2. #2
    Registered User
    Join Date
    12-05-2013
    Location
    Utah
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Workbook Open Event

    I've figured it out. Was easier than I thought.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Workbook Open Event

    Hi, cameron213,

    Quote Originally Posted by Forum Rule#6
    If you solve a problem yourself before anyone else has responded, post your solution to complete the thread.
    Maybe
    Private Sub Workbook_Open()
    Dim rngCell As Range
    Dim blnShow As Boolean
      
    For Each rngCell In Sheets("Sheet1").Range("D2:D" & Sheets("Sheet1").Range("A" & Rows.count).End(xlUp).Row)
      With rngCell
        If Month(Date) = Month(.Value) And Year(Date) = Year(.Value) Then
          blnShow = True
          Exit For
        End If
      End With
    Next rngCell
    
      
    With Sheets("Sheet1").ToggleButton1
      If blnShow Then
        .Visible = True
        .BackColor = RGB(255, 0, 0)
        .Caption = "Re-Visit"
        .Font.Bold = True
        .Font.Size = 18
      Else
        .Visible = False
      End If
    End With
    
    End Sub
    Code goes into ThisWorkbook.

    If you found a solution by yourself you should consider to mark the thread as Solved via Thread Tools over the first post of the thread

    Ciao,
    Holger
    Last edited by HaHoBe; 12-07-2013 at 06:48 AM.
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. WorkBook open Event
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-30-2011, 06:02 PM
  2. WorkBook Open Event?
    By zplugger in forum Excel General
    Replies: 7
    Last Post: 12-10-2011, 02:28 AM
  3. Open workbook event
    By pmguerra in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-24-2010, 09:31 AM
  4. Open Workbook Event
    By newbie13 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2008, 11:56 AM
  5. [SOLVED] Workbook open event
    By hans.domian@de.man-mn.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2006, 06:00 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1