Hi all,
I have a script which opens a user-defined workbook, and later on I need to be able to activate that workbook. I have the filepath for the workbook defined, and I've been able to pull the filename from the path and store it as a variable. However, I get a Runtime Error '9': Subscript out of range notification whenever I try to activate the workbook using the variable I have set. Yet, when I copy and paste the variable contents into my Activate command, the script works.
Dim fNameAndPath As Variant
fNameAndPath = Application.GetOpenFilename(FileFilter:="All Files (*.), *.", Title:="Select File To Be Opened")
If fNameAndPath = False Then Exit Sub
Workbooks.Open fileName:=fNameAndPath
'Dim filepath As String
'filepath = fNameAndPath
' Title = Right(filepath, Len(filepath) - InStrRev(filepath, " \ "))
Dim fso As New FileSystemObject
Dim fileName As String
fileName = fso.GetFileName(fNameAndPath)
Windows("fileName").Activate
Bookmarks