Require assistance with setting up a macro.
The macro the way it’s currently setup reads a filename in a cell reference (data extraction worksheet, cell reference b7) and opens that file, copies data back to the main workbook and then opens the next file (data extraction worksheet, cell reference b8). Before the file copy, it unhides a worksheet (where it’s copying from).
I need assistance with closing the files opened (in cell reference b7 and b8) within the macro, and no need to save.
Sub Open_ExistingWorkbook()
filetoopen = ThisWorkbook.Worksheets("data extraction").Range("b7")
Workbooks.Open Filename:=filetoopen
Sheets("Payspace").Visible = True
Sheets("Payspace").Select
Range("A4").Select
Range("A4:D117").Select
Selection.Copy
Windows("T&O PaySpace upload template_ 2019 - test.xlsm").Activate
Sheets("Location A").Select
Range("A7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-21
Sheets("Data extraction").Select
Range("A16").Select
filetoopen = ThisWorkbook.Worksheets("data extraction").Range("b8")
Workbooks.Open Filename:=filetoopen
Sheets("Payspace").Visible = True
Sheets("Payspace").Select
Range("A4").Select
Range("A4:D117").Select
Selection.Copy
Windows("T&O PaySpace upload template_ 2019 - test.xlsm").Activate
Sheets("Location B").Select
Range("A7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-21
Sheets("Data extraction").Select
Range("A16").Select
End Sub
Bookmarks