import worksheet from an outside workbook

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hello I am trying to see if there is a way to import sheets from a closed workbook into my current workbook. I have some code to allow a user to select the file and get the file path, i am trying to see if now with given a table called "ShtNames" on the tab called "File Input" if there is a way to go through that table if the user were to type the names of the files they want to bring over into this workbook. I provided the table example also and would like the have the file path printed in cell B2 just for reference. Also keeping the same naming of the tabs that are coming over

VBA Code:
[CODE=vba]
Sub addSheet()


Dim filePicker As FileDialog
Dim path As String

Set filePicker = Application.FileDialog(msoFileDialogFilePicker)
    With filePicker
    .Title = "Please select File"
    .AllowMultiSelect = False
    .ButtonName = "Confirm"
        If .Show = -1 Then
            path = .SelectedItems(1)
        Else
            End
        End If
    End With

'Workbooks.Open fileName:=path
       

Dim sourceWB As Workbook
Dim targetWB As Workbook
'
Set targetWB = ThisWorkbook
Set soruceWb = Workbooks.Open(path)


sourceWB.Close
[/CODE]


Book1.xlsm
ABC
1File Path:
2
3Sheets to bring over
4Sheet 1
5Sheet 2
6Sheet 3
7
8
9
File Input
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi. To better understand, the user is going to manually type the sheet names into the File Input tab and these will be the sheets that need to be copied. If so, how would they know the sheet names? Will the options of sheet names always be the same?
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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