I'm trying to open a file which could have a different name everyday but will always contain '1234'. After that, copy and paste various rows of data etc. Problem i'm having now is that I used the macro function to record but I'm unable to use windows.activate to switch to the correct files to copy and paste
sPath = "C:\Users\kings\OneDrive\Desktop\operation\"
sWildcard = "*123*.*"
sFile = Dir(sPath & sWildcard)
If sFile <> "" Then
sWorkbook = sPath & sFile
Workbooks.Open sWorkbook
Else
MsgBox "File Not Found"
' Exit Sub '// optionaly exit the subroutine so that it does not try to continue //
End If
Windows(sWorkbook).Activate
Getting "runtime error 9 subscript out of range" on Windows(sWorkbook).