ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy Sheet in another workbook (https://www.excelbanter.com/excel-programming/328531-copy-sheet-another-workbook.html)

Vasant Nanavati

Copy Sheet in another workbook
 
Perhaps (untested):

ExcelAppx.Workbooks("book1.xls").Sheets("Gulf").Co py _
After:=ExcelApp.Workbooks("book2.xls").Sheets(1)

Not quite sure why you need to open 2 instances of Excel, though.

--

Vasant

"Khaled Eid" wrote in message
...
Hi,
from a VBA code I am trying to copy Sheet1 from book1 to book2. I use
the following code:
'****** Start Code *************
Dim ExcelApp As New Excel.Application
Dim ExcelAppx As New Excel.Application

ExcelApp.Workbooks.Open "D:\book2.xls", False, False
ExcelAppx.Workbooks.Open "D:\book1.xls", False, False

ExcelAppx.Visible = True
ExcelApp.Visible = True

ExcelAppx.Sheets("Gulf").Copy after:=ExcelApp.Sheets(1)
'****** End Code *************

when I run the above code I get the following error:
Run-Time error '1004'
copy method of worksheet class failed


Any good suggestions


Khaled Eid










Khaled Eid

Copy Sheet in another workbook
 
Hi,
from a VBA code I am trying to copy Sheet1 from book1 to book2. I use
the following code:
'****** Start Code *************
Dim ExcelApp As New Excel.Application
Dim ExcelAppx As New Excel.Application

ExcelApp.Workbooks.Open "D:\book2.xls", False, False
ExcelAppx.Workbooks.Open "D:\book1.xls", False, False

ExcelAppx.Visible = True
ExcelApp.Visible = True

ExcelAppx.Sheets("Gulf").Copy after:=ExcelApp.Sheets(1)
'****** End Code *************

when I run the above code I get the following error:
Run-Time error '1004'
copy method of worksheet class failed


Any good suggestions


Khaled Eid








Khaled Eid

Copy Sheet in another workbook
 
Thanks a Lot it worked fine, definitly I am using one instant of excel but
the code I wrote is one of the tests that I am trying to check.

Anyway thank you again, I appreciate it


"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Perhaps (untested):

ExcelAppx.Workbooks("book1.xls").Sheets("Gulf").Co py _
After:=ExcelApp.Workbooks("book2.xls").Sheets(1)

Not quite sure why you need to open 2 instances of Excel, though.

--

Vasant

"Khaled Eid" wrote in message
...
Hi,
from a VBA code I am trying to copy Sheet1 from book1 to book2. I use
the following code:
'****** Start Code *************
Dim ExcelApp As New Excel.Application
Dim ExcelAppx As New Excel.Application

ExcelApp.Workbooks.Open "D:\book2.xls", False, False
ExcelAppx.Workbooks.Open "D:\book1.xls", False, False

ExcelAppx.Visible = True
ExcelApp.Visible = True

ExcelAppx.Sheets("Gulf").Copy after:=ExcelApp.Sheets(1)
'****** End Code *************

when I run the above code I get the following error:
Run-Time error '1004'
copy method of worksheet class failed


Any good suggestions


Khaled Eid













All times are GMT +1. The time now is 03:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com