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
25 Comments »
Leave a comment
-
Archives
- July 2011 (1)
- March 2011 (1)
- November 2010 (1)
- November 2008 (4)
- October 2008 (2)
- 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
https://quicktestprofessional.wordpress.com/category/excel-automation/
Comment by quicktestprofessional | June 18, 2008 |
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 |
Dear Mohan,
The website is really helping good work 🙂
thanx a lot
Comment by amrita | June 8, 2009 |
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 |
same dought for me also do you got reply for this
Comment by manoj | January 21, 2014 |
Please tell how to copy from one excel (sheet1) to another one excel2 (sheet2) when excel 2 is already open and i dnt want to close it
Please reply soon .. its urgent
Comment by sweta | November 27, 2009 |
just comment the create command and add open command and get file and the use copy
Comment by kumar | October 31, 2013 |
Hi Mohan,
Thanks for sharing these information. Its really helping a lot of people like me who are learning QTP.
Keep up the good work.
Once again..Thank you
Comment by Manju | March 6, 2010 |
Hello
i have to append data from multiple sheets into one sheet.
i have tried all but can’t get thru.
could you please mail me the solution
Thanks in advance.
Comment by saurabh | April 13, 2010 |
Hi Mohan
Thanks for sharing these information. Its really helping a lot of people like me who are learning QTP.
Keep up the good work.
Once again..Thank you
Comment by Lokeswar Reddy B | May 17, 2010 |
I was having trouble figuring out what the two lines for properly copying & pasting would be. Thanks, it came in handy.
Comment by Dennis | July 16, 2010 |
How to copy values from one input excel sheet to different tabs in another excel sheet.
Comment by Kanchana | December 14, 2010 |
Hi Mohan ,
objWorkSheet.Range(“A1″).PasteSpecial Paste = xlValues.
Please explain me this script i.e:-What is the function of Pastespecial and how Qtp will recognize xlValues as it is not defined as Dim.
Comment by Shishir Pandey | February 1, 2011 |
I have run this script in qtp-10.0 it is showing the error as “Excel.Application” not found
Comment by jagmohan | May 20, 2011 |
please resolve this query
Comment by jagmohan | May 20, 2011 |
For the very first line of code, it says that “ActiveX component can’t create objExcel. Why is this???
Comment by Elena Buhay | July 15, 2011 |
Hi Mohan, thanks a lot for your great work..I used the excel automation part for coying 1 file into another and worked fine. But it pops up with 2 excel window. 1 for if I wanna replace the content and other one is if I wanna continue. I tried with recording and also recovery scenario to enter/click yes on those 2 windows. But nothing is working. I have manually click OK button. Can you please suggest? Will really appreciate…
Comment by Arifur | July 26, 2011 |
[…] Copy an excel sheet to another excel […]
Pingback by tallada | September 18, 2012 |
Hi,
I wan’t know , how to activate some file (excel ,Prn etc) without use its “Name”
thanks.
Comment by shasika liyanage | September 26, 2012 |
Hi,
I am new to qtp.
how and where can i execute this code?
Please help.
Comment by indumathi | October 29, 2012 |
just open qtp window and type the code dont copy paste it wont work and run it ok
Comment by kumar | October 31, 2013 |
I have two excel sheets, where in it does vlookup based on Pathname attribute, the matched machines will be copied to second excelsheet.
So, colud you please help me how to automate vlookup and provide some macros for the same
Comment by indumathi | October 29, 2012 |
QTP Scripts Blog—http://funandknowledge.blogspot.com
Comment by QTP Scripts | March 13, 2013 |
Hi, Is there a way we can also copy the formating from once excel to the other ?
I was able to do in VBA but not able to do in QTP
Comment by mmk | June 20, 2013 |
super example some more advance file system we want in QTP
Comment by kumar | October 31, 2013 |