Excel VBA Add Custom List on Open

TopCase

New Member
Joined
May 17, 2018
Messages
4
Hello,

I have a distributable workbook that utilizes custom sort lists. I would like to include a macro in the file that (when someone else opens the file) automatically runs and imports the custom lists.

I have a macro that adds the lists but the issue is on repeated use. Currently, if the user already has a custom list like the one trying to be imported, an error occurs. I would like to delete that list before importing the new one (or skip the import). Any tips would be greatly appreciated, thanks!

Here is what I have:

Sub Customlistadd()
'
' Customlistadd Macro
'
'
Application.AddCustomList ListArray:=Range("'Custom Sort'!A2:A31")
Application.AddCustomList ListArray:=Range("'Custom Sort'!C2:C33")
Application.AddCustomList ListArray:=Range("'Custom Sort'!E2:E8")
Application.AddCustomList ListArray:=Range("'Custom Sort'!G2:G5")
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hello,

I have a distributable workbook that utilizes custom sort lists. I would like to include a macro in the file that (when someone else opens the file) automatically runs and imports the custom lists.

I have a macro that adds the lists but the issue is on repeated use. Currently, if the user already has a custom list like the one trying to be imported, an error occurs. I would like to delete that list before importing the new one (or skip the import). Any tips would be greatly appreciated, thanks!

Here is what I have:

Sub Customlistadd()
'
' Customlistadd Macro
'
'
Application.AddCustomList ListArray:=Range("'Custom Sort'!A2:A31")
Application.AddCustomList ListArray:=Range("'Custom Sort'!C2:C33")
Application.AddCustomList ListArray:=Range("'Custom Sort'!E2:E8")
Application.AddCustomList ListArray:=Range("'Custom Sort'!G2:G5")
End Sub

Code:
Sub Customlistadd()
'
' Customlistadd Macro
'
On error goto 0 ' make it exit out
Application.AddCustomList ListArray:=Range("'Custom Sort'!A2:A31")
Application.AddCustomList ListArray:=Range("'Custom Sort'!C2:C33")
Application.AddCustomList ListArray:=Range("'Custom Sort'!E2:E8")
Application.AddCustomList ListArray:=Range("'Custom Sort'!G2:G5")
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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