MistakesWereMade
Board Regular
- Joined
- May 22, 2019
- Messages
- 103
I have a program that opens up various workbooks, and I would like to have A1 automatically selected after a workbook is opened.
My code is below. The opened excel file's name is saved as variable "OpeningVar".
My code is below. The opened excel file's name is saved as variable "OpeningVar".
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\w34\PS\"
OpeningVar = Me.ComboBox1.Value
Me.ComboBox1.Clear
myRange.Clear
On Error Resume Next
Set Wbk = Workbooks.Open(Pth & OpeningVar)
On Error GoTo 0
If Wbk Is Nothing Then
MsgBox "Workbook not found."
End If
End Sub