PC Review


Reply
Thread Tools Rate Thread

Detecting user cancel out of "File Open" input box

 
 
vrzimmerm@hotmail.com
Guest
Posts: n/a
 
      25th Sep 2007
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.

 
Reply With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      25th Sep 2007
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.


 
Reply With Quote
 
vrzimmerm@hotmail.com
Guest
Posts: n/a
 
      25th Sep 2007
On Sep 25, 8:57 am, 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.


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 With Quote
 
JW
Guest
Posts: n/a
 
      25th Sep 2007
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
vrzimm...@hotmail.com wrote:
> On Sep 25, 8:57 am, 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.

>
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting user input of "" and replacing with VBA computed default MachAngle Microsoft Excel Programming 1 26th Apr 2009 03:58 PM
I can't "Open" a downloaded template. Only "Save" and "Cancel" Dave Microsoft Word Document Management 1 4th Apr 2008 02:28 PM
"DriverSigningPolicy" setting is set to "Ignore" but it still asks for user input garyf@softsource.co.za Windows XP Setup 0 26th May 2005 12:01 PM
<input id="iPhoto" type="file" size="20" runat="server"> Mark Sandfox Microsoft ASP .NET 1 11th May 2004 02:58 AM
Double "Open/Save/Cancel/More Info" dialog when downloading text file from ASP.NET =?Utf-8?B?dGhleWFz?= Microsoft ASP .NET 7 5th May 2004 12:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:48 AM.