Quantcast
Channel: Micro Focus QTP (UFT) Forums - All Forums
Viewing all articles
Browse latest Browse all 1653

Need help on excel datatable operations

$
0
0
Hi

I am new to QTP. Need help on excel datatable operations.

I have 4 excel files in a folder. I need to convert all excel files to CSV.

I have written below code, but somehow it wont work. getting error message as "Open method of Workbooks class failed".

Please find below my code:


Option Explicit 
Dim TotRow,i,ExcelObj,Sourcefile,TargetFile

TotRow =  DataTable.LocalSheet.GetRowCount

For i = 1 To TotRow

    Set ExcelObj = CreateObject("Excel.Application")
    ExcelObj.DisplayAlerts = False
    ExcelObj.Visible  = False  
    
''    Sourcefile = Datatable("SourceFile",dtlocalsheet)
''    
''    TargetFile = Datatable("TargetFile",dtlocalsheet)
    
    ExcelObj.Workbooks.Open Datatable("SourceFile",dtlocalsheet)
    ExcelObj.SaveAs Datatable("TargetFile",dtlocalsheet)
    ExcelObj.Application.Quit

Next


Datatable Details:

          Sourcefile                                                [i]TargetFile[/i]

C:\QTP\ExpectedReports\a.xlsx               C:\QTP\ExpectedReports\a.csv
C:\QTP\ExpectedReports\b.xlsx               C:\QTP\ExpectedReports\b.csv
C:\QTP\ExpectedReports\c.xlsx               C:\QTP\ExpectedReports\c.csv
C:\QTP\ExpectedReports\d.xlsx               C:\QTP\ExpectedReports\d.csv


Please Note: If I provide full path of sourcefile and targetfile then code works. but I don't want to enter those each time as there are 1000 of files in a folder which I need to concert to CSV.

Thanks,
Sushant

Viewing all articles
Browse latest Browse all 1653

Trending Articles