I'd probably steer away from excel or any external lists etc. for your first VBA project.
The below example is taken from the acad developer help files.
the basics of it is: It is loading a particular linetype (in this case CENTER) from the acad.lin file.
Sub Example_Load()
' This example attempts to load the linetype "CENTER" from
' the acad.lin file. If the linetype already exists, then
' a message is displayed.
Dim linetypeName As String
linetypeName = "CENTER"
' Load "CENTER" line type from acad.lin file
On Error Resume Next ' trap any load errors
ThisDrawing.Linetypes.Load linetypeName, "acad.lin"
' If the name already exists, then notify user
If Err.Description = "Duplicate record name" Then
MsgBox "A line type named '" & linetypeName & "' already exists.", , "Load Example"
End If
End Sub
The following code will list all the linetypes loaded in the current drawing.
however there is no way to tell what the current/default linetype file is.
(at least none that I know of, or at least a heap of code to compare linetype structure against linetype files etc. etc. blah blah blah. to much unless really needed.)
The list of linetypes within the current drawing will be placed into a listbox called ListBox1. So you will need to create a form with a listbaox of that name, or change to a name of your choosing.
Sub ListLinetypes()
Dim objLinetype As AcadLineType
Dim iCounter As Integer
Dim i As Variant
Dim MyList() As String
iCounter = 0
For Each objLinetype In ThisDrawing.Linetypes
' check if linetype comes from an xref linetype name will contain "|"
If InStrRev(objLinetype.Name, "|") = 0 Then
ReDim Preserve MyList(iCounter)
MyList(iCounter) = objLinetype.Name
iCounter = iCounter + 1
End If
Next
' sort list order, calls the SortArray function
SortArray MyList
' put the sorted list in the ListBox
For i = LBound(MyList) To UBound(MyList)
ListBox1.AddItem MyList(i)
Next
End Sub
The following code is used to sort a list.
place the code into a module.
Option Explicit
'begin array sort
Public Sub SortArray(StringArray() As String)
Dim loopOuter As Integer
Dim loopInner As Integer
Dim i As Integer
For loopOuter = UBound(StringArray) To _
LBound(StringArray) Step -1
For loopInner = 0 To loopOuter - 1
If UCase(StringArray(loopInner)) > _
UCase(StringArray(loopInner + 1)) Then
Swap StringArray(loopInner), _
StringArray(loopInner + 1)
End If
Next loopInner
Next loopOuter
End Sub
Private Sub Swap(a As String, b As String)
Dim c As String: c = a: a = b: b = c
End Sub
'End array sort
So the basic task that you might like to try is.
Create a form that contains 2 listboxes. One of which can contain all the currently loaded linetypes within the drawing. The second listbox can contain a list of linetypes available from a selected linetype file.
For simplicity you may wish to code in a default linetype file.
Then add a button to load a selected linetype from the available list to load into the drawing. Then that linetype should appear in the current linetypes list.
Following that you may then wish to add another button that will open a select file dialog to browse & select a linetype file of your choice.
Hope that all makes sense & is of good use.