Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Detecting user cancel out of "File Open" input box

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Detecting user cancel out of "File Open" input box

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

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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Detecting user cancel out of "File Open" input box

On Sep 25, 8:57 am, 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.


For some reason it's not recognizing that the user canceled out of the
"open file" window as the message box isn't even being displayed.
The error is found in a spot lower down in my code (where it has
assumed that a file had been opened.) When the user cancels out
all I want is for the "Open file" window to close and then the user
should be brought back to the file where the macro resides.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Detecting user cancel out of "File Open" input box

Sub fOpenTest()
Dim FName As Variant
FName = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
If FName = False Or FName = "" Then Exit Sub
'Rest of your code here
End Sub
wrote:
On Sep 25, 8:57 am, 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.


For some reason it's not recognizing that the user canceled out of the
"open file" window as the message box isn't even being displayed.
The error is found in a spot lower down in my code (where it has
assumed that a file had been opened.) When the user cancels out
all I want is for the "Open file" window to close and then the user
should be brought back to the file where the macro resides.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Excel Discussion (Misc queries) 0 April 23rd 09 08:53 PM
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Setting up and Configuration of Excel 0 April 23rd 09 08:53 PM
cancel the "Getting Started" Dialogue Box when I open XL/Word jazzy1 Setting up and Configuration of Excel 1 May 2nd 08 12:53 AM
input box - I don't need the "cancel" button Paula Excel Programming 3 November 4th 05 03:35 PM
Problem- Recording macros for "file save" and "File open" tritaco Excel Programming 1 April 22nd 04 06:15 PM


All times are GMT +1. The time now is 07:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"