Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default How to copy a worksheet from one workbook to another in vb6

Hi All,

I have 2 workbook(i.e. 1.xls & 2.xls) at 2 different location, I want
to copy all the worksheets present in 2.xls to 1.xls file using vb6.

I am trying to open both the files and then trying with this code...

Workbooks(2.xls).Worksheets("sheet2").Copy _
After:=Workbooks(1.xls).Worksheets("sheet1")

I am getting "subscript out of range" error.... can u plz help me...

Thanks in Advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default How to copy a worksheet from one workbook to another in vb6

try... with quotes in the workbooks object....

Workbooks("2.xls").Worksheets("sheet2").Copy _
After:=Workbooks("1.xls").Worksheets("sheet1")




SpiderSwamy wrote:
Hi All,

I have 2 workbook(i.e. 1.xls & 2.xls) at 2 different location, I want
to copy all the worksheets present in 2.xls to 1.xls file using vb6.

I am trying to open both the files and then trying with this code...

Workbooks(2.xls).Worksheets("sheet2").Copy _
After:=Workbooks(1.xls).Worksheets("sheet1")

I am getting "subscript out of range" error.... can u plz help me...

Thanks in Advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default How to copy a worksheet from one workbook to another in vb6

Hi Sorry man..

real code is like this where strFile = 2.xls and strFinalReport = 1.xls

Workbooks(strFile).Worksheets("summary").Copy _
After:=Workbooks(strFinalReport).Worksheets("sheet 1")

thanks
Swamy

wrote:
try... with quotes in the workbooks object....

Workbooks("2.xls").Worksheets("sheet2").Copy _
After:=Workbooks("1.xls").Worksheets("sheet1")




SpiderSwamy wrote:
Hi All,

I have 2 workbook(i.e. 1.xls & 2.xls) at 2 different location, I want
to copy all the worksheets present in 2.xls to 1.xls file using vb6.

I am trying to open both the files and then trying with this code...

Workbooks(2.xls).Worksheets("sheet2").Copy _
After:=Workbooks(1.xls).Worksheets("sheet1")

I am getting "subscript out of range" error.... can u plz help me...

Thanks in Advance.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to copy a worksheet from one workbook to another in vb6

Make sure the workbook names are in double quotes, too:

Workbooks("2.xls").Worksheets("sheet2").Copy _
After:=Workbooks("1.xls").Worksheets("sheet1")



SpiderSwamy wrote:

Hi All,

I have 2 workbook(i.e. 1.xls & 2.xls) at 2 different location, I want
to copy all the worksheets present in 2.xls to 1.xls file using vb6.

I am trying to open both the files and then trying with this code...

Workbooks(2.xls).Worksheets("sheet2").Copy _
After:=Workbooks(1.xls).Worksheets("sheet1")

I am getting "subscript out of range" error.... can u plz help me...

Thanks in Advance.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to copy a worksheet from one workbook to another in vb6

Subscript out of range will mean that either you don't have an open workbook
with the name in the strFile variable -- or the strFinalReport variable.

Or you don't have a "Summary" sheet in that first workbook--or you don't have
"Sheet1" in the strFinalReport workbook.



SpiderSwamy wrote:

Hi Sorry man..

real code is like this where strFile = 2.xls and strFinalReport = 1.xls

Workbooks(strFile).Worksheets("summary").Copy _
After:=Workbooks(strFinalReport).Worksheets("sheet 1")

thanks
Swamy

wrote:
try... with quotes in the workbooks object....

Workbooks("2.xls").Worksheets("sheet2").Copy _
After:=Workbooks("1.xls").Worksheets("sheet1")




SpiderSwamy wrote:
Hi All,

I have 2 workbook(i.e. 1.xls & 2.xls) at 2 different location, I want
to copy all the worksheets present in 2.xls to 1.xls file using vb6.

I am trying to open both the files and then trying with this code...

Workbooks(2.xls).Worksheets("sheet2").Copy _
After:=Workbooks(1.xls).Worksheets("sheet1")

I am getting "subscript out of range" error.... can u plz help me...

Thanks in Advance.


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default How to copy a worksheet from one workbook to another in vb6

I am using this code and making it visible so that I can see whether
the file is open or not..
Set apexcel = CreateObject("Excel.application")
apexcel.Workbooks.Open strReportFile ' to open where the file is
located.
apexcel.Visible = True ' make = True,So you can see Excel
Set mywbD = apexcel.Workbooks(1)


Set apexcel = CreateObject("Excel.application")
apexcel.Workbooks.Open strFileName ' to open where the file is located.
'apexcel.Workbooks.Open ' to open where the file is located.
apexcel.Visible = True ' make = True,So you can see Excel
Set mywbS = apexcel.Workbooks(1)
strFile = File1.List(n)(i.e. strFile = 2.xls)

' code to copy worksheet from One workbook to another EXISTING workbook
Workbooks(strFile).Worksheets("graphs").Copy _
After:=Workbooks(strFinalReport).Worksheets("sheet 1")

and I am to see both the files and sheets are exisiting but...
when i put a watch on them. it comes as below...

Worksheets("Sheet1") : Nothing is here : Object/Worksheet :
Generate.Combine_Click
Worksheets("graphs") : <Subscript out of range : Integer :
Generate.Combine_Click

as u can see for Worksheets("Sheet1") its typr = Object/Worksheet.
for Worksheets("graphs") its type = Integer

I think i have some problem here. not able to solve...
thnx

Dave Peterson wrote:
Subscript out of range will mean that either you don't have an open workbook
with the name in the strFile variable -- or the strFinalReport variable.

Or you don't have a "Summary" sheet in that first workbook--or you don't have
"Sheet1" in the strFinalReport workbook.



SpiderSwamy wrote:

Hi Sorry man..

real code is like this where strFile = 2.xls and strFinalReport = 1.xls

Workbooks(strFile).Worksheets("summary").Copy _
After:=Workbooks(strFinalReport).Worksheets("sheet 1")

thanks
Swamy

wrote:
try... with quotes in the workbooks object....

Workbooks("2.xls").Worksheets("sheet2").Copy _
After:=Workbooks("1.xls").Worksheets("sheet1")



SpiderSwamy wrote:
Hi All,

I have 2 workbook(i.e. 1.xls & 2.xls) at 2 different location, I want
to copy all the worksheets present in 2.xls to 1.xls file using vb6.

I am trying to open both the files and then trying with this code...

Workbooks(2.xls).Worksheets("sheet2").Copy _
After:=Workbooks(1.xls).Worksheets("sheet1")

I am getting "subscript out of range" error.... can u plz help me...

Thanks in Advance.


--

Dave Peterson


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default How to copy a worksheet from one workbook to another in vb6

Hi All I got the Poblem solved here is the solution:

Set xlAppS = New Excel.Application
Set wbS = xlAppS.Workbooks.Open(strFileName)
xlAppS.Visible = True
' strFileName = Source file from where u want to copy the sheet

Dim BkName As String
Dim NumSht As Integer
Dim BegSht As Integer

'Starts with second sheet - replace with index number of starting
sheet.
BegSht = 2
'Moves two sheets - replace with number of sheets to move.
NumSht = 1
BkName = ActiveWorkbook.Name

For x = 1 To NumSht
'Moves second sheet in source to designated workbook.
'this code is for moving a worksheet from one workbook to another
'Workbooks(BkName).Sheets(BegSht).Move
Befo=Workbooks("Test.xls").Sheets(1)
'this code is for copying a worksheet from 1 workbook to another
Workbooks(BkName).Sheets(BegSht).Copy _
Befo=Workbooks("Test.xls").Sheets(1)
'In each loop, the next sheet in line becomes indexed as
number 2.
'Replace Test.xls with the full name of the target workbook you
want.
Next
' *Note --- Don't forget keep both the files in same folder.

Thanks
Swamy

SpiderSwamy wrote:

I am using this code and making it visible so that I can see whether
the file is open or not..
Set apexcel = CreateObject("Excel.application")
apexcel.Workbooks.Open strReportFile ' to open where the file is
located.
apexcel.Visible = True ' make = True,So you can see Excel
Set mywbD = apexcel.Workbooks(1)


Set apexcel = CreateObject("Excel.application")
apexcel.Workbooks.Open strFileName ' to open where the file is located.
'apexcel.Workbooks.Open ' to open where the file is located.
apexcel.Visible = True ' make = True,So you can see Excel
Set mywbS = apexcel.Workbooks(1)
strFile = File1.List(n)(i.e. strFile = 2.xls)

' code to copy worksheet from One workbook to another EXISTING workbook
Workbooks(strFile).Worksheets("graphs").Copy _
After:=Workbooks(strFinalReport).Worksheets("sheet 1")

and I am to see both the files and sheets are exisiting but...
when i put a watch on them. it comes as below...

Worksheets("Sheet1") : Nothing is here : Object/Worksheet :
Generate.Combine_Click
Worksheets("graphs") : <Subscript out of range : Integer :
Generate.Combine_Click

as u can see for Worksheets("Sheet1") its typr = Object/Worksheet.
for Worksheets("graphs") its type = Integer

I think i have some problem here. not able to solve...
thnx

Dave Peterson wrote:
Subscript out of range will mean that either you don't have an open workbook
with the name in the strFile variable -- or the strFinalReport variable.

Or you don't have a "Summary" sheet in that first workbook--or you don't have
"Sheet1" in the strFinalReport workbook.



SpiderSwamy wrote:

Hi Sorry man..

real code is like this where strFile = 2.xls and strFinalReport = 1.xls

Workbooks(strFile).Worksheets("summary").Copy _
After:=Workbooks(strFinalReport).Worksheets("sheet 1")

thanks
Swamy

wrote:
try... with quotes in the workbooks object....

Workbooks("2.xls").Worksheets("sheet2").Copy _
After:=Workbooks("1.xls").Worksheets("sheet1")



SpiderSwamy wrote:
Hi All,

I have 2 workbook(i.e. 1.xls & 2.xls) at 2 different location, I want
to copy all the worksheets present in 2.xls to 1.xls file using vb6.

I am trying to open both the files and then trying with this code...

Workbooks(2.xls).Worksheets("sheet2").Copy _
After:=Workbooks(1.xls).Worksheets("sheet1")

I am getting "subscript out of range" error.... can u plz help me...

Thanks in Advance.


--

Dave Peterson


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy worksheet from one workbook to a master workbook mvannatta Excel Worksheet Functions 3 April 15th 09 08:32 PM
Copy Worksheet from one Workbook to another Workbook Autumn Dreams Excel Discussion (Misc queries) 5 September 12th 08 10:55 PM
Copy Data from Workbook into specific Worksheet in other Workbook? kingdt Excel Discussion (Misc queries) 1 March 16th 06 06:55 PM
How do I copy a worksheet form a workbook in my workbook Neil Atkinson Excel Programming 1 October 12th 05 12:23 PM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM


All times are GMT +1. The time now is 05:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"