I have a userform with combobox1 and near a commanbutton1.
How to show in combobox only all .xls file in c:\mydir\mysubdir\ and after the selection via commandbutton1 open the actuall workbook in new excel session?
Possible.?
OPEN workbook via combobox
-
- Administrator
- Posts: 78534
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: OPEN workbook via combobox
Put the following code in the userform module:
Code: Select all
Private Const strFolder = "c:\mydir\mysubdir\"
Private Sub CommandButton1_Click()
If Me.ListBox1.ListIndex = -1 Then
MsgBox "Please select a filename.", vbExclamation
Else
Workbooks.Open strFolder & Me.ListBox1
End If
End Sub
Private Sub UserForm_Initialize()
Dim strFile As String
strFile = Dir(strFolder & "*.xls")
Do While Not strFile = ""
Me.ListBox1.AddItem strFile
strFile = Dir
Loop
End Sub
Best wishes,
Hans
Hans