2016-09-21 17 views
-1

私は動的な文字列配列を宣言し、次に他の各プロシージャを呼び出したいと思います。これは私が持っているものです、私はそれが動作すると思ったが、私は間違いを続けている。ワード内のVBA配列

Option Explicit 

Sub Main() 

    Public ListArr() As String 

    Application.Run "Get_Input_List" 

End Sub 

Function Get_Input_List(ByRef ListArr() As String) As String 

    Dim list As String 
    Dim MesBox As String 

    list = InputBox("Please enters word to sort using a comma with no space to separate", "Words") 

    ListArr = Split(list, ",") 

    MsgBox ListArr(1) 

End Function 

答えて

1

ここにいくつかの問題があります。まず、Publicは、モジュールレベル変数のアクセス修飾子としてのみ使用できます。ローカル変数ではないため、Dim ListArr() As Stringにする必要があります。次に、同じプロジェクトのプロシージャを呼び出すときにApplication.Runを使用する必要はありません。 になった場合は、必要なパラメータを渡していません。ByRefApplication.Run経由で渡すことはできません。第3に、Get_Input_Listは関数なので、おそらくSplitの結果を返すべきです。今は常にvbNullStringを返します。私はあなたがこのような何かを探していると推測しています:

Option Explicit 

Sub Main() 
    Dim ListArr() As String 
    ListArr = Get_Input_List 

    Dim inputWord As Variant 
    For Each inputWord In ListArr 
     MsgBox inputWord 
    Next 
End Sub 

Function Get_Input_List() As String() 
    Dim list As String 

    list = InputBox("Please enter words to sort separated with a comma and no spaces", "Words") 
    Get_Input_List = Split(list, ",") 
End Function