Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2010 VBA error try to copy a workseet from another workbook into same

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I want to copy a worksheet from another workbook into the workbook where the VBA cod is running.
Getting and Error #9 Subscript out of range.

Code:
 Workbooks("Master.HC.file.Test.Macros.xlsx").Sheets("BASE").Copy Workbooks("PACE.Feb.2013.02.15.13 TEST.xls")


DougP
 
Sorry for posting then figuring it out on my own, anyway here is what I discovered.
The names of the workbooks are refered to by just the workbook names not their entire path.
The workbook being copied from WorkbookSource has to open in Excel.

Code:
    Dim WorkbookCurrent, WorkbookSource As String
    WorkbookCurrent = Application.ActiveWorkbook.name
    WorkbookSource = "soure workbook name"
    Dim sh As Worksheet, wb As Workbook
    Set wb = Workbooks(WorkbookCurrent)
    For Each sh In Workbooks(WorkbookSource).Worksheets
       sh.Copy After:=wb.Sheets(wb.Sheets.Count)
    Next sh
[code]

DougP
 
hi,
Code:
FromWorkbookObject.FromWorksheetObject.Copy _
  ToWorkbookObject[b].ToWorksheetObject[/b]

In other words, copy from a sheet ro another workbook Before or After an existing sheet.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
into the workbook where the VBA cod is running
So, you may use ActiveWorkbook as source and ThisWorkbook as destination.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top