Avatar of Culwatrnca11
Culwatrnca11
Flag for United States of America asked on

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

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!"
Microsoft ExcelVB ScriptMicrosoft OfficeVBA

Avatar of undefined
Last Comment
Shums Faruk

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Shums Faruk

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Shums Faruk

No comment has been added to this question in more than 14 days, so it is now classified as abandoned.

I have recommended this question be closed as Shums (42046951)

If you feel this question should be closed differently, post an objection and a moderator will read all objections and then close it as they feel fit. If no one objects, this question will be closed automatically the way described above.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23