Micro Focus QTP (UFT) Forums
How to give the file name dynamically using variable name - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to give the file name dynamically using variable name (/Thread-How-to-give-the-file-name-dynamically-using-variable-name)



How to give the file name dynamically using variable name - vnsk - 10-12-2011

[i]
Code:
Dim xlApp
Dim xlBook
Dim xlSheet
Dim x
x= sanity
Set xlApp=CreateObject("Excel.Application")
Set xlBook=xlApp.workbooks.add
Set xlSheet=xlBook.activesheet
xlSheet.cells(1,1)="Oppurtunity Id"
xlSheet.cells(1,2)= MSG16
xlBook.saveas "C:\[color=#FF0000]"x".[/color]xls"
xlApp.quit


Here iam trying to save file name as sanity.xls
Where i am taking file name from variable x
But iam getting error
How to save the file name like this



RE: How to give the file name dynamically using variable name - parminderdhiman84 - 10-12-2011

try this:

xlBook.saveas "C:\"&x&".xls"


RE: How to give the file name dynamically using variable name - vnsk - 10-12-2011

Getting:
SaveAs method of Workbook class failedLine (14): "xlBook.saveas "C:\Documents and Settings\SXCHA19\Desktop\"&x&".xls""


RE: How to give the file name dynamically using variable name - sreekanth chilam - 10-12-2011

Hi,

Here we go...
Code:
Dim xlApp
Dim xlBook
Dim xlSheet
Dim x
x= "sanity"
Set xlApp=CreateObject("Excel.Application")
Set xlBook=xlApp.workbooks.add
Set xlSheet=xlBook.Activesheet
xlSheet.cells(1,1)="Oppurtunity Id"
xlSheet.cells(1,2)= "MSG16"
xlBook.saveas "C:\"&x&".xls"
xlApp.quit
Set xlApp=Nothing



RE: How to give the file name dynamically using variable name - vnsk - 10-13-2011

Thank you