troubleshooting Question

Merge Sheet from one workbook to another - assistance with existing code

Avatar of Culwatrnca11
Culwatrnca11Flag for United States of America asked on
Microsoft ExcelVB ScriptMicrosoft OfficeVBA
2 Comments1 Solution80 ViewsLast Modified:
I aquired this code to pull in (Sheet1) from another workbook and merge it into my master workbook. Its working but..

The problem is when the tab is pulled in from WB2 it needs to be placed infront of Sheet1, its currently coming in and going to the last tab. How do you bring it in so it is 1st tab? also once it has been pulled into the master file I need to protect this sheet before saving and exit.  

Dim objExcel
    Dim objWB1
    Dim objWB2
    Dim ws
    Set objExcel = CreateObject("Excel.Application")
    objExcel.DisplayAlerts = False
    Set objWB1 = objExcel.Workbooks.Open("c:\SOURCE_TAB_Benefits.xlsm")
    Set objWB2 = objExcel.Workbooks.Open("c:\BENEFITS_Run.xlsx")
    For Each ws In objWB1.Sheets
        ws.Copy objWB2.Sheets(objWB2.Sheets1.Count)
       

Next
    objWB1.Close False
    objWB2.Save
    objWB2.Close
    With objExcel
       
        .DisplayAlerts = True
        .Quit
    End With
    Set objExcel = Nothing
    MsgBox "Done!"
ASKER CERTIFIED SOLUTION
Shums
Excel VBA Developer
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros