Trying to open a file using a listbox selection. My code says quote "Compile error: User-defined type not defined" on the first line?

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
Private Sub ListBox3_Click()

Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.folder

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("\\TGS-SRV01\Share\ShopFloor\PRODUCTION\DLS Carworker")

Dim I As Long
For I = 0 To ListBox3.ListCount - 1
If ListBox3.Selected(I) Then
Workbook.Open objFolder & ListBox3.List(I)

End If
Next I

End Sub
 
You haven't asked for anything else. I have answered you question and provided a solution for you.
Sorry I should have said at the start the listbox is to do Various task as well as opening spreadsheets?
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Please start a new thread and list your objectives/questions as this one was specifically to open a workbook so you would get a better response.
 
Upvote 0
Sorry, should have said that I need a list box to do multiple functions not just opening spreadsheets?
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top