New to VBA and just trying to make some edits to some existing code. I have basically copied a pre-existing form and module and changed names from "Appendix" to "Drawing" as I am trying to replicate what the piece of code already produces for a table of appendices, for my drawings. However, when I try and run the form I get Compile error: Variable not defined with lstDrawings highlighted.
Private Sub UserForm_Initialize()
Dim iNextDrawID As Integer
Dim sNextDrawLet As String
Dim iChar As Integer
Dim iDraw As Integer
Dim sLet As String
Dim sDesc As String
Dim bBlankAfter As Boolean
iNextDrawID = 1
On Error Resume Next
iNextDrawID = ActiveDocument.CustomDocumentProperties("NextDrawingID").Value
On Error GoTo 0
sNextDrawLet = "A"
On Error Resume Next
sNextDrawLet = ActiveDocument.CustomDocumentProperties("NextDrawing").Value
On Error GoTo 0
If sNextDrawLet <> "A" Then
For iChar = Asc("A") To Asc(sNextDrawLet) - 1
For iDraw = 1 To iNextDrawID - 1
sLet = ""
On Error Resume Next
sLet = ActiveDocument.CustomDocumentProperties("Drawing" & Format(iDraw, "00") & "_Let").Value
On Error GoTo 0
If sLet = Chr(iChar) Then
sDesc = ""
bBlankAfter = False
On Error Resume Next
sDesc = ActiveDocument.CustomDocumentProperties("Drawing" & Format(iDraw, "00") & "_Desc").Value
bBlankAfter = CBool(ActiveDocument.CustomDocumentProperties("Drawing" & Format(iDraw, "00") & "_BlankPage").Value)
On Error GoTo 0
With lstDrawings
.AddItem sLet
.Column(1, .ListCount - 1) = sDesc
If bBlankAfter Then
.Column(2, .ListCount - 1) = "Yes"
Else
.Column(2, .ListCount - 1) = "No"
End If
.Column(4, .ListCount - 1) = iDraw
End With
Exit For
End If
Next
Next
End If
End Sub
Is this something that should be defined in my global module which I am missing?
Any help is much appreciated.
Bookmarks