Quick test professional

QTP Tips QTP codes QTP Faqs and more

Copy an excel sheet to another excel

Following is the code to copy the conntents of a sheet in one excel to another excel sheet

Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(“C:\Documents and Settings\mohan.kakarla\Desktop\1.xls”)
Set objWorkbook2= objExcel.Workbooks.Open(“C:\Documents and Settings\mohan.kakarla\Desktop\2.xls”)
objWorkbook1.Worksheets(“Sheet1″).UsedRange.Copy
objWorkbook2.Worksheets(“Sheet1″).Range(“A1″).PasteSpecial Paste =xlValues
objWorkbook1.save
objWorkbook2.save
objWorkbook1.close
objWorkbook2.close
set objExcel=nothing

 Author: Mohan Kakarla

June 9, 2008 - Posted by quicktestprofessional | Excel Automation, Uncategorized | , , , | 4 Comments

4 Comments »

  1. Vineet,
    Please search before posting the comment
    try here

    http://quicktestprofessional.wordpress.com/category/excel-automation/

    Comment by quicktestprofessional | June 18, 2008 | Reply

  2. I want to enter dynamic values in “Range” field like first time the script will copy the Range “B5:Z5″ and second time
    “B15:Z15″ and so on. So I would like to make the script dynamic. Is there any way can I do it or using loops etc.? please help me out.

    Thanks.

    Comment by Simran | December 11, 2008 | Reply

  3. Dear Mohan,
    The website is really helping good work :)
    thanx a lot

    Comment by amrita | June 8, 2009 | Reply

  4. Hi Mohan,

    I am new to QTP.. These articles are nice.. Thanks a lot for providing these kind of help.
    I have one doubt regarding PasteSpecial

    objWorkSheet.Range(“A1″).PasteSpecial Paste = xlValues

    Here what is the exact syntax for PasteSpecial
    or what u mean by “Paste” and “xlValues”
    As per my knowledge it is variables only, Am I right?
    So I can use any other variables also for this. But I didnt get the exact meaning of this usage.. Can u plz explain this?

    Comment by SriDevi | July 22, 2009 | Reply


Leave a comment