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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Sheet from Open Workbook

Status
Not open for further replies.

uncled

Technical User
May 24, 2006
18
US
I built an Excel reporting application that will create a Summary worksheet report on the fly. However, I want to allow the user to copy a previous Summary worksheet from another Open workbook (or closed) instead of generating a new Summary sheet.

So basically, I would like to cycle through any open workbooks looking for a worksheet titled "Summary" and if found, copy into the active/current workbook, otherwise, generate on the fly.

I can't figure out how to cycle through open workbooks to search for the Summary sheet.

thanks in advance for any advice!!
 
I can't figure out how to cycle through open workbooks
A starting point:
For Each wb in Application.Workbooks

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the tip PHV, got me going in the right direction! However, now I'm trying to cycle through the worksheets of each open workbook to determine whether a worksheet exists. Here are the loops I have...I can't figure out how to reference the workbook and it's associated worksheets (i've currently got ActiveWorkbook in the code which is only reference the worksheets in my target workbook, not the other open workbooks)

For Each wb In Excel.Application.Workbooks
For Each ws In ActiveWorkbook.Worksheets
If ws.Name = "PIPELINE" Then
Worksheets("PIPELINE").Copy After:=ActiveSheet
Worksheets("PIPELINE").Name = myWrksheet
End If
Next
Next

Thanks again for any assistance!
 




Code:
For Each wb In Excel.Application.Workbooks
        For Each ws In [s]ActiveWorkbook[/s] [b]wb[/b].Worksheets
            If ws.Name = "PIPELINE" Then
                [b]ws[/b].Copy After:=ActiveSheet
                [b]ws[/b].Name = myWrksheet
            End If
        Next


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks Skip...that got me going in the right direction, howver, I'm not sure what I'm doing wrong here, but I can't seem to get the targeted worksheet copied to the main file. I've declared CurrentWorkbook as a String and assigned the source workbook. When I attempt the Copy command, I get a subscript out of range error and can't seem to figure out how to tell the program where to copy the worksheet.

Here's what I've got

For Each wb In Excel.Application.Workbooks
For Each ws In wb.Worksheets
If ws.Name = "PIPELINE" Then
Sheets("PIPELINE").Copy Before:=Workbooks(CurrentWorkbook).Sheets(1)
Worksheets("PIPELINE").Name = myWrksheet
End If
Next
Next

thanks!
 





Why are you using Sheets("PIPELINE") and Worksheets("PIPELINE"), UNQUALLIFIED to a workbook, when ws IS THAT SHEET???
Code:
            If ws.Name = "PIPELINE" Then
                ws.Copy Before:=Workbooks(CurrentWorkbook).Sheets(1)
                ws.Name = myWrksheet
            End If

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top