Copying sheets from external workbook

Lee Rabbit

New Member
Joined
Apr 30, 2020
Messages
43
Office Version
  1. 2010
Platform
  1. Windows
Hi,

I have the below code to copy sheet values into a new workbook.

I am trying to include a couple of sheets from external workbooks that are located in the same folder as the original.

Workbooks are named "EXPORT 1" sheet name "TEST 1" and "EXPORT 2" sheet name "TEST 2".

Is there a way to merge this action into the existing code?

Thanks in advance.
Lee

VBA Code:
Sub Duplicate_Workbook()

Dim ws As Worksheet
Dim strFileName As String

    strFileName = InputBox("Type a name for the new workbook", "File Name")
    If Trim(strFileName) = vbNullString Then Exit Sub
    
    ActiveWorkbook.Sheets(Array("INVOICE 1", "INVOICE 2", "INVOICE 3", "INVOICE 4", "INVOICE 5", "INVOICE 6", "INVOICE 7")).Copy
    
    For Each ws In ActiveWorkbook.Worksheets
    
        ws.UsedRange.Value = ws.UsedRange.Value
        ws.Rows(3).Delete
        ws.Shapes("CopyRow").Delete
        ws.Shapes("SortDrivers").Delete
        ws.Shapes("DeleteENTRY").Delete
        
    Next ws
    
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:="C:\PDF\" & strFileName & ".xlsx", FileFormat:=xlOpenXMLWorkbook
    Application.DisplayAlerts = True
    ActiveWorkbook.Close
    
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,213,489
Messages
6,113,954
Members
448,535
Latest member
alrossman

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