Import an External File into a Data Table
Source code
'This example imports data from external files into the Data Table and sets parameters
'for the test through the Data Table. It shows how you can send parameters to a test by
'setting the Data Table values before running the test.
'There is no unsaved test currently open in UFT One.
'For more information, see the example for the Test.SaveAs method.
'UFT opens with the add-ins required for the test.
'For more information, see the example for the Test.GetAssociatedAddins method.

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtOptions 'As QuickTest.RunResultsOptions ' Declare a Run Results Options object variable
Set qtApp = CreateObject("QuickTest.Application") ' Create a Application object
qtApp.Launch ' Start UFT One
qtApp.Visible = True ' Make the UFT One application visible

' Open the test
qtApp.Open "C:\Tests\Test1", False ' Open a test named "Test1"

' Import data to the design-time Data Table and then add new data
qtApp.Test.DataTable.Import "C:\Data.xls" ' Import data from an external file
qtApp.Test.DataTable.ImportSheet "C:\Tables.xls", 1, "Action1" ' Import a single sheet
qtApp.Test.DataTable.GlobalSheet.GetParameter("Started") = Now ' Set test run starting time
qtApp.Test.DataTable.GlobalSheet("ParamCount") = 45 ' Set a parameter for the test using the Data Table

' Run the test
Set qtOptions = CreateObject("QuickTest.RunResultsOptions") ' Create a Results Option object
qtOptions.ResultsLocation = "<TempLocation>" ' Set the Results location to temporary location
qtApp.Test.Run qtOptions, True ' Run the test and wait for it to finish before continuing the automation script

' Set additional values in the design-time Data Table
qtApp.Test.DataTable.GlobalSheet("Ended") = Now ' Set test's run ending time
qtApp.Test.DataTable.GlobalSheet("RanBy") = "James" ' Set the "RanBy" cell

' Save the Run-time Data Table
qtApp.Test.LastRunResults.DataTable.Export "C:\Runtime.xls" ' Save the run-time Data Table to a file

qtApp.Quit ' Exit UFT One
Set qtOptions = Nothing ' Release the Run Results Options object
Set qtApp = Nothing ' Release the Application object