1

I have a folder containing over 100 worksheets and named 1,2,3, etc but I can only open the workbooks by adding .xlsx to the number of the workbook in the combobox.

Is there a way to go around this?

Private Sub CommandButton1_Click()
   Dim filename As String
   Dim filepath As String

   filename = ComboBox1.Value
   filepath = "D:\e-library\MSC\DIS7000\data\"

   Workbooks.Open (filepath & filename)
End Sub
ashleedawg
  • 20,365
  • 9
  • 72
  • 105
dejioni
  • 37
  • 6

1 Answers1

0

Yes - you can get through that bu adding .xlsx to the filename programmatically instead of manually. Try this:

Private Sub CommandButton1_Click()
   Dim filename As String
   Dim filepath As String

   filename = ComboBox1.Value
   filepath = "D:\e-library\MSC\DIS7000\data\"

   Workbooks.Open (filepath & filename & ".xlsx")
End Sub
ashleedawg
  • 20,365
  • 9
  • 72
  • 105
  • Also I have a detailed description of the difference between Form Controls and ActiveX controls [here](https://stackoverflow.com/a/49263001/8112776). – ashleedawg Apr 01 '18 at 13:25