Merging Several sheets into Master Doc..

C

chunkylover57

How do I get this code to import all the new sheets into the current
active worksheet...Right now this opens a new book...I want this to
work in the active book..

Sub GetSheets()
Dim sPath As String, i As Long
Dim varr As Variant
Dim wkbk As Workbook
Dim wkbk1 As Workbook
Set wkbk1 = ActiveWorkbook
sPath = "C:\$user\PCO\"
varr = Array("itsr.xls", "tsr.xls", "tsm.xls", "tm.xls")
For i = LBound(varr) To UBound(varr)
Set wkbk = Workbooks.Open(sPath & varr(i))
If i = LBound(varr) Then
wkbk.Worksheets.Copy
Set wkbk1 = ActiveWorkbook
Else
wkbk.Worksheets.Copy After:=wkbk1. _
Worksheets(wkbk1.Worksheets.Count)
End If
wkbk.Close SaveChanges:=False
Next
End Sub
 
B

BrianB

'------------------------------------------------
Sub GetSheets()
Dim sPath As String, i As Long
Dim varr As Variant
Dim wkbk As Workbook
Dim wkbk1 As Workbook
'--------------------------
Set wkbk1 = ActiveWorkbook
sPath = "C:\$user\PCO\"
varr = Array("itsr.xls", "tsr.xls", "tsm.xls", "tm.xls")
'-------------------------------------------
For i = LBound(varr) To UBound(varr)
Set wkbk = Workbooks.Open(sPath & varr(i))
wkbk.Worksheets.Copy After:=wkbk1. _
Worksheets(wkbk1.Worksheets.Count)
wkbk.Close SaveChanges:=False
Next
End Sub
'-------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top