Micro Focus QTP (UFT) Forums

Full Version: Folder and file name
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How to dynamically give a folder and filename?
Hi Shruti,

Do you think your query gives enough info on what you want to achieve?

Please elaborate your need.
Hi Ptabhta,
i am unable to create the folder name and filename dynamically using QTP for storing the values inside the xl,with the values.

hope this clarifies.
Hi Shruti,

If i have understood correctly, you want create a folder and inside that folder create an excel file, write some data in the excel file and save it, all dynamically. If that is the case, the code below might help you achieve that:

Code:
Dim folderPath, folderName, xlFileName

//Provide folder path, folder name and excel file name

folderPath = "C:\"
folderName = "MyFolder"
xlFileName = "MyExcel.xls"

//Create File System Object
Set fso = CreateObject("Scripting.FileSystemObject")
//Build the folder path
newPath = fso.BuildPath(folderPath,folderName)

//Create the folder if it is not created already
If fso.FolderExists(newPath) <> True Then
    fso.CreateFolder(newPath)
End If

//Create Excel object
Set xlApp = CreateObject("Excel.Application")
Set xlSheet=createObject("Excel.sheet")

//Write into excel file and save it inside the newly created folder
xlSheet.ActiveSheet.cells(1,1).value=1111
xlSheet.SaveAs newPath&"\"&xlFileName

Set xlSheet = Nothing
Set xlApp = Nothing
Set fso = Nothing

Hope this helps you. Also hope next time around you spell my name correct Smile