将数据从excel导出到word,同时功能

时间:2014-10-09 10:43:42

标签: excel vba ms-word export word-vba

我正在尝试将数据从excel导出到word但是在while语句的乞讨时出现了问题。出于某种原因,我在第ReDim Preserve zPList(zIndex) As personClass行收到错误,错误为Subscript out of range

有人可以帮忙吗?

Public Sub GetExcelData(ByRef zPList() As personClass, ByRef zIndex As Integer)

    Dim tempStr As String
    tempStr = ""
    Dim row As Integer
    row = 2

    While tempStr <> "zzz"

        zindez = zIndex + 1
        ReDim Preserve zPList(zIndex) As personClass
        Set zPList(zIndex) = New personClass

        Range("A" + CStr(row)).Select
        zPList(zIndex).fname = ActiveCell.text

        Range("B" + CStr(row)).Select
        zPList(zIndex).lname = ActiveCell.text

        Range("C" + CStr(row)).Select
        zPList(zIndex).Email = ActiveCell.text

        Range("D" + CStr(row)).Select
        zPList(zIndex).phoneN = ActiveCell.text

        row = row + 1
        Range("A" + CStr(row)).Select
        tempStr = ActiveCell.text

    Wend

End Sub

0 个答案:

没有答案