Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50194

Copy Sheet From Separate Instance of Excel

$
0
0
I'm trying to copy a sheet from two identically named workbooks. The only way i can think to do this is to open the file with the sheet to be copied in a separate instance of excel. but i can't get the copy code right. maybe there's a different way to do this altogether

Just a snippet

Code:

            Dim oldWB As Excel.Application
            Set oldWB = CreateObject("Excel.Application")

            'Make sure the path exists then open
                If Dir(prior_path) <> "" Then
                    Set oldWS = oldWB.Workbooks.Open _
                            (FileName:=prior_path, ReadOnly:=True)
                    oldWB.Visible = True
                Else
                    GoTo skip1:
                End If
           
            DoEvents
           
            'This is what bugs up.... Assuming i have to activate it or something but it bugs then too
                oldWS.Sheets("Copy Sheet").Copy After:=NewWS.Sheets("Sheet 1"), Name:="Copy Sheet"
                oldWS.Workbooks.Close
skip1:
            Set oldLB = Nothing


Viewing all articles
Browse latest Browse all 50194

Trending Articles