Declare and Initialize String Array in VBA

前端 未结 6 1687
刺人心
刺人心 2020-11-28 02:54

This should work according to another stack overflow post but its not:

Dim arrWsNames As String() = {\"Value1\", \"Value2\"}

Can anyone let

6条回答
  •  Happy的楠姐
    2020-11-28 03:28

    In the specific case of a String array you could initialize the array using the Split Function as it returns a String array rather than a Variant array:

    Dim arrWsNames() As String
    arrWsNames = Split("Value1,Value2,Value3", ",")
    

    This allows you to avoid using the Variant data type and preserve the desired type for arrWsNames.

提交回复
热议问题