Copy and Paste Worksheet From Different Workbooks With a Variable

DaveHappyNorm

New Member
Joined
Jul 22, 2018
Messages
15
Hello all

I was hoping some could help me with the following:-

I am trying to copy a sheet from one workbook to another workbook but repeat this process over and over again.

I have an open workbook called TIF.
I want to open a different workbook called Template, copy the sheet "Current"
Paste the sheet "Current" to the workbook TIF
Close the Workbook Template.
Because I will be copying the sheet "Current" from the Template workbook into different workbooks i.e. TIF TIF1 TIF2 TIF3 etc I stored the workbook name as a variable.

The code I have is as follows:-

Dim Site_Name as string
Site_Name = TIF.xlsx

Workbooks.Open Filename:= _
"C:\Template.xlsx"
Sheets("CURRENT").Copy Before:="C:\Work" & Site_Name

Windows("Template.xlsx").Activate
ActiveWindow.Close

But this code does not work.

Can anyone help with a solution?

Thank you.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Untested but this should allow you to copy the template sheet to an open workbook whose name starts with TIF, provided no other workbooks with a name starting with TIF are open.
Code:
Dim wb As Workbook, Site_Name As String
'assumes you have only one workbook with a name that starts with TIF open.
For Each wb In Workbooks
    If wb.Name Like "TIF*" Then
        Site_Name = wb.Name
        Exit For
    End If
Next wb
Workbooks.Open Filename:="C:\Template.xlsx"
Sheets("CURRENT").Copy Before:=Workbooks(Site_Name).Sheets(1)   'change sheet to suit
Workbooks("Template.xlsx").Close savechanges:=False
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top