We help IT Professionals succeed at work.
Get Started

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

Last Modified: 2017-04-01
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)

    objWB1.Close False
    With objExcel
        .DisplayAlerts = True
    End With
    Set objExcel = Nothing
    MsgBox "Done!"
Watch Question
Excel VBA Developer
Distinguished Expert 2018
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE