MistakesWereMade
Board Regular
- Joined
- May 22, 2019
- Messages
- 103
My code below opens an excel file using a user form. My code for some reason hides the ribbon every OTHER time it opens an excel file rather than every consecutive time. Am I missing something? Is there a way to narrow down the hide ribbon to the new opened workbook and active sheet?
Code:
Private Sub CommandButton1_Click()
Dim Wbk As Workbook
Dim Pth As String
Dim myRange As Range
Set myRange = ThisWorkbook.Worksheets("Data").Range("E2")
Pth = Environ("Userprofile") & "\Desktop\Project 1 - Master Folder\Packaging Specs\"
OpeningVar = Me.ComboBox1.Value
Me.ComboBox1.Clear
myRange.Clear
On Error Resume Next
Set Wbk = Workbooks.Open(Pth & OpeningVar)
CommandBars.ExecuteMso "HideRibbon"
Wbk.ActiveSheet.Range("A1").Select
On Error GoTo 0
If Wbk Is Nothing Then
MsgBox "Workbook not found."
End If
End Sub