ArrayList Compile Error user defined type not defined

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hello, i am getting an error, compile error: user defined type not defined
i am not sure why this is happening
getting it in this code at this part of the code:

tblTabsImport As ArrayList

Code below:

VBA Code:
Private Sub CommandButton2_Click()

Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False

'Getting arrayList of tabs to import
'
'Dim tabsToImport As ArrayList
'Set tabsToImport = New ArrayList

Dim tblTabsImport As ArrayList
Set tblTabsImport = New ArrayList

Dim wb As Workbook
Set wb = Workbooks.Open(fileName:=Me.TextBox1.Text)

Dim i As LongPtr
Dim tempSht As Worksheet

Dim lo As ListObject

For i = 0 To Me.ListBox1.ListCount - 1
    If Me.ListBox1.Selected(i) = True Then
        tblTabsImport.Add Me.ListBox1.list(i)
    End If
Next i

For i = 0 To tblTabsImport.count - 1
    wb.Worksheets(tblTabsImport(i)).Copy After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.count)
Next i

On Error Resume Next
ThisWorkbook.ChangeLink Name:=wb.Name, NewName:=ThisWorkbook.Name
On Error GoTo 0

Unload Me

Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True


End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Shouldn't it just be
Dim tblTabsImport As New ArrayList
Using Set seems a bit wrong as you will be adding items to a list, I'm no expert on the specifics of ArrayList but I'm fairly sure you just need to declare it at the start.

Edit:- quick check on some ArrayList info, as far as I can see you need to 'Set' it to an object variable if you're using late binding. If you're using early binding then the line above should suffice.
 
Upvote 0
Declaring As New is generally regarded as bad practice, but I think the main issue here is that you need a reference to the mscorlib library (if I remember correctly) to use objects from the .net runtime.
 
Upvote 0

Forum statistics

Threads
1,216,561
Messages
6,131,416
Members
449,651
Latest member
Jacobs22

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