Nightlytic
Member
So, found code below:
Works like a charm. Copies all sheets of another workbook into my current workbook. very handy at my work. But requires me to go into vba and insert the path.
My questions:
1. How can I make this so that the current selection becomes the variable used as path? For example, if I was to select range A1 which has a folder path c:\temp\Test.xls written in it, and run the code via a keyboard shortcut, it performs the operation and copies the worksheets?
2. If I had a list of paths in range A1:A6, different paths, and had buttons in B1:B6 for each line to import the path shown to the left, if clicked. Sort of like the offset argument?
Code:
Sub CopyAll()
'sub copies the worksheets within another, closed excel file pastes them into current open file
Dim Wb1 As Workbook
Dim Wb2 As Workbook
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
Set Wb1 = Workbooks.Open("c:\temp\Test.xls")
'need to change location above to a relative reference
Set Wb2 = ThisWorkbook
Wb1.Sheets.Copy Before:=Wb2.Sheets(6)
'modifly number in brackets in line above to change after how many sheets to paste new tabs
Wb1.Close False
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
End With
End Sub
Works like a charm. Copies all sheets of another workbook into my current workbook. very handy at my work. But requires me to go into vba and insert the path.
My questions:
1. How can I make this so that the current selection becomes the variable used as path? For example, if I was to select range A1 which has a folder path c:\temp\Test.xls written in it, and run the code via a keyboard shortcut, it performs the operation and copies the worksheets?
2. If I had a list of paths in range A1:A6, different paths, and had buttons in B1:B6 for each line to import the path shown to the left, if clicked. Sort of like the offset argument?
Last edited by a moderator: