Here is my entire code to open a file from a ComboBox in a userform. How can i alter it to get set the file that it opens as WB1 because this would allow me to reference it in the macro. This code was given to me by someone on this site and i am still pretty new to vba so i am limited. I actually want to incorporate another combobox with it to open another file from the same folder. How would I do that? Thank you in advance for the help.
Option Explicit
Const userDir As String = "C:\Users\Public"
Private Sub CommandButton1_Click()
' This is for Excel files
Workbooks.Open Filename:=userDir & Me.ComboBox1
End Sub
Private Sub UserForm_Activate()
Dim fname As String
Dim target As Range
Me.ComboBox1.Clear
fname = Dir(userDir & "\*", vbNormal)
Do While fname <> ""
Me.ComboBox1.AddItem fname
fname = Dir
Loop
End Sub
Bookmarks