VBS Script Error 800A0401

Michael s 1 Reputation point
2022-03-22T01:28:58.303+00:00

I have made a script in VBA and I am wanting to launch it from the desktop with a .VBS extension.
When I click on the file I get a Script Host error stating line 3 char 12 Expected end of statement code 800A0401
Any help would be great
Private Sub UserForm_Initialize()
'Creates and assigns the Array to the ListBox when the form loads.
Dim mylist As Variant
mylist = Array("TEST", "AARDS", "NGAARDA", "LARRAKIA","2CUZ", "NG MEDIA", "PAKAM", "PAW MEDIA", "PY MEDIA", "QRAM", "TEABBA", "6WR", "TSIMA")
ListBox1.List = mylist

End Sub

Private Sub CommandButton1_Click()

    Dim olApp As Outlook.Application
    Dim olemail As Outlook.MailItem

    'TEST
        If ListBox1.Selected(0) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\0.TEST.msg")

            olemail.Send
        MsgBox ListBox1.List(0)
        End If
    'AARDS
        If ListBox1.Selected(1) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\1.AARDS.msg")

            olemail.Send
        MsgBox ListBox1.List(1)
        End If
    'NGAARDA
        If ListBox1.Selected(2) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\2.NGAARDA.msg")

            olemail.Send
        MsgBox ListBox1.List(2)
        End If
    'LARRAKIA
        If ListBox1.Selected(3) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\3.LARRAKIA.msg")

            olemail.Send
        MsgBox ListBox1.List(3)
        End If
    '2CUZ
        If ListBox1.Selected(4) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\4.2CUZ.msg")

            olemail.Send
        MsgBox ListBox1.List(4)
        End If
    'NG MEDIA
        If ListBox1.Selected(5) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\5.NG MEDIA.msg")

            olemail.Send
        MsgBox ListBox1.List(5)
        End If
    'PAKAM
        If ListBox1.Selected(6) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\6.PAKAM.msg")

            olemail.Send
        MsgBox ListBox1.List(6)
        End If
    'PAW MEDIA
        If ListBox1.Selected(7) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\7.PAW MEDIA.msg")

            olemail.Send
        MsgBox ListBox1.List(7)
        End If
    'PY MEDIA
        If ListBox1.Selected(8) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\8.PY MEDIA.msg")

            olemail.Send
        MsgBox ListBox1.List(8)
        End If
    'QRAM
        If ListBox1.Selected(9) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\9.QRAM.msg")

            olemail.Send
        MsgBox ListBox1.List(9)
        End If
    'TEABBA
        If ListBox1.Selected(10) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\10.TEABBA.msg")

            olemail.Send
        MsgBox ListBox1.List(10)
        End If

    ' 6WR
        If ListBox1.Selected(11) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\11.6WR.msg")

            olemail.Send
        MsgBox ListBox1.List(11)
        End If

    'TSIMA
        If ListBox1.Selected(12) = True Then
            Set olApp = New Outlook.Application
            Set olemail = olApp.CreateItemFromTemplate("O:\MIS\1 ZIP Templates\12.TSIMA.msg")

            olemail.Send
        MsgBox ListBox1.List(12)
        End If


End Sub
Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2022-03-22T20:00:27.547+00:00

    I think that "As" cannot be used in VBS. Try simpler declarations:

    Dim mylist
    Dim olApp
    Dim olemail

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.