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
[/CODE]
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
Book1.xlsm | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | File Path: | ||||
2 | |||||
3 | Sheets to bring over | ||||
4 | Sheet 1 | ||||
5 | Sheet 2 | ||||
6 | Sheet 3 | ||||
7 | |||||
8 | |||||
9 | |||||
File Input |
Last edited: