Search code examples
excelvba

If Then Else On Open VBA


Hi could someone help me in a very basic VBA formula? I need an Excel tab to be visible or not depending on the name of the file. So if the filename is called "CI Q (New_User)", the YourWeek tab is visible, otherwise it's hidden.

Tried this but doesnt work:

Private Sub Workbook_Open()
   
 If (Wb.Name) Like "CI Q (New_User).xlsm" Then     
   Sheets("YourWeek").Visible = True
 Else
   Sheets("YourWeek").Visible = False       
 End If

End Sub

Solution

  • Try this:

    Private sub Workbook_Open()
    
       if Thisworkbook.Name = "CI Q (New_User).xlsm" then
          Sheets("YourWeek").Visible = True
       Else
          Sheets("YourWeek").Visible = False   
       end if
    
    end sub