Microsoft KB Archive/114258

{|
 * width="100%"|

HOWTO: Transfer an Array from VB 3.0 to a Microsoft Excel Sheet

 * }

Q114258

-

The information in this article applies to:


 * Microsoft Visual Basic, version 3.0
 * Microsoft Excel for Windows, version 5.0

-

SUMMARY
This article discusses how you can use Microsoft Excel version 5.0, Visual Basic version 3.0, and OLE automation to transfer the contents of an array from a Visual Basic application to a Microsoft Excel worksheet.

MORE INFORMATION
OLE Automation allows you use a Visual Basic application to control another application, such as Microsoft Excel. In order to manipulate the object of another application, you need to identify it with a programmatic identifier. Programmatic identifiers are registered in your system when you install an application. The programmatic identifiers for Microsoft Excel 5.0 are listed in the following table:

                             Represents this This identifier           Microsoft Excel 5.0 object -

Excel.Application.5       Application Excel.Sheet.5             Sheet Excel.Chart.5             Chart The following example demonstrates how to create a Visual Basic version 3.0 executable program that can be run from a Microsoft Excel Visual Basic macro to transfer the contents of an array to the active worksheet in Microsoft Excel.

WARNING: Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line continuation character. For more information about Visual Basic for Applications programming style, see the "Programming Style in This Manual" section in the "Document Conventions" section of the "Visual Basic User's Guide."

Example

 * 1) Start Visual Basic version 3.0.
 * 2) Enter the following code for the Click event for Form1:
 * 3) From the File menu, choose Make EXE File to compile the code.
 * 4) Quit Visual Basic.
 * 5) Start Microsoft Excel 5.0.
 * 6) From the File menu, choose New.
 * 7) From the Insert menu, choose Macro, and then choose Module.
 * 8) Enter the following code on the Visual Basic module (Note this example assumes the .EXE file created in step 3 above is located on C:\VB\TEST.EXE):
 * 9) Select "Sheet1" in the active workbook.
 * 10) From the Tools menu, choose Macro.
 * 11) Select the TransferArrayFromVBApp macro, and then choose the Run button.
 * 12) Form1 will appear. Click the form to start the transfer of the array to the active worksheet ("Sheet1"). When the transfer is complete, a message box stating that the transfer is complete will appear. Choose OK.