Link to home
Start Free TrialLog in
Avatar of Juan Velasquez
Juan VelasquezFlag for United States of America

asked on

subscript out of range error when attempting to activate file

Hello,
The attached function returns a string containing the file path of the selected file.
I am getting a "Subscript Out of Range Error in the calling procedure in the second line of the following calling code.  When I used a debug.print statement after the first line, the correct file was being called.  I am running Excel 2003

strSourceFilePath = GetFile    
Windows(strSourceFilePath).Activate
Public Function GetFile() As String
    
    With Application.FileDialog(msoFileDialogOpen)
        .InitialFileName = Application.DefaultFilePath & "\"
        .Title = "Please select source file"
        .Show
        If .SelectedItems.Count = 0 Then
            GetFile = "No File Selected"
        Else
            GetFile = .SelectedItems(1)
        End If
    End With
    
End Function

Open in new window

Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Try something like

strSourceFilePath = GetFile    
for each win in windows
  if win.name=getfile then
    Win.Activate
  endif
next win
Avatar of Juan Velasquez

ASKER

I've tried it and I get a "Object does not support this property or method" at
If win.Name = GetFile Then
ASKER CERTIFIED SOLUTION
Avatar of Juan Velasquez
Juan Velasquez
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So does this mean that you do not need any more assistance?
I just wanted to confirm and it looks like the solution  I posted earlier will work fine
The solution worked perfectly.