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
4 Comments »
Leave a comment
-
Archives
- November 2008 (4)
- October 2008 (1)
- September 2008 (2)
- June 2008 (1)
- March 2008 (4)
- February 2008 (44)
-
Categories
- Automated Test Script Creation Process
- Automating MS Word
- Automating QC
- Automation Object Model For QTP
- Backward compatability in QTP
- Browser Scripts
- COM and QTP
- compare 2 text files
- Descriptive programming
- Descriptive Programming and Child Objetcs
- Dictonary Object
- DotNetFactory
- Excel Automation
- Extra Topics
- Files and Folders
- General Standards to be followed in Test scripts
- New Features In QTP9.5
- QC-OTA
- QTP Additional Faqs
- QTP Faqs
- QTP Naming Convention
- QTP Tips and Faqs
- Running stored procedures from QTP
- Send keyboard keys
- Uncategorized
- Uninstall a software using QTP
- Uninstall a software using vbscript
- Update data in a database
- VBScript and IE Automation
- VBScript Faqs and Useful resources
- What’s New in Quick Test Pro 9.0
- Whats New in QTP 9.5
- XML Scripting
-
RSS
Entries RSS
Comments RSS

Vineet,
Please search before posting the comment
try here
http://quicktestprofessional.wordpress.com/category/excel-automation/
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.
Dear Mohan,
The website is really helping good work
thanx a lot
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?