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 Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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