Your code works fine for me. It opens the file that the user selects,
shows a message box stating that "file open canceled", and then closes
the workbook that it opened. Don't see what that is accomplishing,
but it did what you want according to your code.
Word of advice, although Excel is supposed to turn DisplayAlerts back
on once a procedure is complete, I still recommend getting in the
habit of turning them back on in your code.
Application.DisplayAlerts = True
vrzimm...@hotmail.com wrote:
> The following macro segment is supposed to detect if the user
> cancelled out of an "Open File" input window, but I keep getting a
> "subscript out of range" error. What am I doing wrong?
>
> Dim FName As Variant
> FName = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
> If Not FName = False Then Workbooks.Open FName
> Application.DisplayAlerts = False
>
> If FName <> False Then
> Set wb = Workbooks.Open(FName)
> MsgBox "File open cancelled"
> wb.Close
> End If
>
> Thanks.
|