I've some problems with my code as it has to open a closed excel file , it works only if the name is short , as the file come automatically out as "OPEN ORDERS 16.05.2018" I'd like to be able to input this without having the rename the file OPEN_ORDER for example as this works with the last one but not the long name.
Sub OOR()
Dim ws As Worksheet
Set ws = Sheets("Sheet 1")
Dim lr As Long
Dim mnt As String, mnt2 As String
Dim xWb As Workbook
ThisWorkbook.UpdateLinks = xlUpdateLinksNever
Application.DisplayAlerts = False
mnt = InputBox("Filename")
mnt2 = "'H:\Documents\[" & mnt & ".xlsx]Sheet 1'" ' Change Sheet1 to the actual tabname
Set xWb = Workbooks.Open("\\data\Documents\" & mnt & ".xlsx")
ActiveWindow.Visible = False
lr = ws.Cells(Rows.Count, "B").End(xlUp).Row
ty = Array("=INDEX(" & mnt & "!$R:$R,MATCH(1,(E2=" & mnt & "!$E:$E)*(J2=" & mnt & "!$J:$J),0))")
ws.Range("R2:R" & lr).FormulaArray = ty
ThisWorkbook.UpdateLinks = xlUpdateLinksAlways
Application.DisplayAlerts = True
xWb.Close savechanges:=False
End Sub
EDIT:
=INDEX(OPEN ORDERS '[16.07.2018]16.07'!$R:$R,MATCH(1,(E5=OPEN ORDERS '[16.07.2018]16.07'!$E:$E)*(J5=OPEN ORDERS '[16.07.2018]16.07'!$J:$J),0))
This is the formula that comes out once the name typed in , and i don't know why it opens OPEN ORDERS '[16.07.2018]16.07
when prompted OPEN ORDERS 16.07.2018 there's probably a problem with the space and the "." but i don't know how to fix it.