Results 1 to 1 of 1

How do I fill an array within an Excel procedure called by Word?

Threaded View

  1. #1
    Registered User
    Join Date
    12-11-2009
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    12

    How do I fill an array within an Excel procedure called by Word?

    I've written a Word VBA procedure that pulls data from multiple Excel documents into a report. It does this by calling several Excel VBA procedures.

    One of those Excel documents contains three columns. I re-use this document a lot and the number of rows is different each time; it can be as few as 2 and has so far gone as high as 30. Row 1 in each column contains a header, such as NAME, INFO, and DATE. Column A is filled with a constant, such as "Bob." Column B contains different text in each row. Column C contains a different date in each row, written out in "January 10, 2012" format.

    Word opens this Excel document and calls an Excel procedure named Report. Report counts the number of rows containing data and passes this number back to Word. I also want it to pass every date in column C back to Word. I'm trying to use an array named Dates for this purpose.

    Within the Word procedure, I have:

    Dim CountA as Integer
    Dim Dates() as String
    XL.Application.Run "'PERSONAL.XLSB'!Report", NumberOfRows, Dates()
    For CountA = 2 To NumberOfRows
       Do some stuff
    Next CountA
    In the Excel procedure named Report, I have:

    Sub Report(NumberOfRows As Integer, ParamArray Dates() As Variant)
    Dim CountB As Integer
    For CountB = 2 To NumberOfRows
       Dates(CountB) = Cells(CountB, 3).Value
    Next CountB
    End Sub
    When I run this, it stops at the line "Dates(CountB) = Cells(CountB, 3).Value" and tells me "An array index is out of range." Any idea on how I can work with this? I'm using Office 2007.

    Thanks!
    Last edited by keris; 01-10-2012 at 11:04 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1