PC Review


Reply
Thread Tools Rate Thread

Capturing 'Cancel' on Applicaiton.Dialogs(xlDialogOpen).Show FilePathAndName

 
 
theSquirrel
Guest
Posts: n/a
 
      6th Sep 2007
Hello there,

I have read many instances of how to use the Open dialog on many
different sites and haven't found a way to capture the 'cancel' button
when there is a file already selected.

Here is the code that I am using:
FilePathAndName= Range("BY35").Value
Application.Dialogs(xlDialogOpen).Show FilePathAndName

I know that there is another way to get the open dialog box using the
following code:
FileName = Application.GetOpenFilename

Even this has problems handling the 'cancel' button when a file was
selected.

Can anyone help?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?cDQ1Y2Fs?=
Guest
Posts: n/a
 
      6th Sep 2007
executing this line:
Result=Application.Dialogs(xlDialogOpen).Show

returns True if a file has been opened, and FALSE if the user presses Cancel.
--
p45cal


"theSquirrel" wrote:

> Hello there,
>
> I have read many instances of how to use the Open dialog on many
> different sites and haven't found a way to capture the 'cancel' button
> when there is a file already selected.
>
> Here is the code that I am using:
> FilePathAndName= Range("BY35").Value
> Application.Dialogs(xlDialogOpen).Show FilePathAndName
>
> I know that there is another way to get the open dialog box using the
> following code:
> FileName = Application.GetOpenFilename
>
> Even this has problems handling the 'cancel' button when a file was
> selected.
>
> Can anyone help?
>
>

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      6th Sep 2007

Sub test()

Filename = Application.GetOpenFilename
If Filename = False Then
MsgBox "User Cancelled!"
End If

'or
If Application.Dialogs(xlDialogOpen).Show("Z:\TEMP\*.xls") = False Then
MsgBox "User Cancelled!"
End If

End Sub



--
Hope that helps.

Vergel Adriano


"theSquirrel" wrote:

> Hello there,
>
> I have read many instances of how to use the Open dialog on many
> different sites and haven't found a way to capture the 'cancel' button
> when there is a file already selected.
>
> Here is the code that I am using:
> FilePathAndName= Range("BY35").Value
> Application.Dialogs(xlDialogOpen).Show FilePathAndName
>
> I know that there is another way to get the open dialog box using the
> following code:
> FileName = Application.GetOpenFilename
>
> Even this has problems handling the 'cancel' button when a file was
> selected.
>
> Can anyone help?
>
>

 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      6th Sep 2007
This is something like what I have used in the past and have never had
any problems, whether a file is selected or not.
s = Application.GetOpenFilename
If s = False Or s = "" Then Exit Sub
MsgBox s

theSquirrel wrote:
> Hello there,
>
> I have read many instances of how to use the Open dialog on many
> different sites and haven't found a way to capture the 'cancel' button
> when there is a file already selected.
>
> Here is the code that I am using:
> FilePathAndName= Range("BY35").Value
> Application.Dialogs(xlDialogOpen).Show FilePathAndName
>
> I know that there is another way to get the open dialog box using the
> following code:
> FileName = Application.GetOpenFilename
>
> Even this has problems handling the 'cancel' button when a file was
> selected.
>
> Can anyone help?


 
Reply With Quote
 
theSquirrel
Guest
Posts: n/a
 
      6th Sep 2007
On Sep 6, 10:36 am, Vergel Adriano
<VergelAdri...@discussions.microsoft.com> wrote:
> Sub test()
>
> Filename = Application.GetOpenFilename
> If Filename = False Then
> MsgBox "User Cancelled!"
> End If
>
> 'or
> If Application.Dialogs(xlDialogOpen).Show("Z:\TEMP\*.xls") = False Then
> MsgBox "User Cancelled!"
> End If
>
> End Sub
>
> --
> Hope that helps.
>
> Vergel Adriano
>
> "theSquirrel" wrote:
> > Hello there,

>
> > I have read many instances of how to use the Open dialog on many
> > different sites and haven't found a way to capture the 'cancel' button
> > when there is a file already selected.

>
> > Here is the code that I am using:
> > FilePathAndName= Range("BY35").Value
> > Application.Dialogs(xlDialogOpen).Show FilePathAndName

>
> > I know that there is another way to get the open dialog box using the
> > following code:
> > FileName = Application.GetOpenFilename

>
> > Even this has problems handling the 'cancel' button when a file was
> > selected.

>
> > Can anyone help?


Vergel...

This is brilliant! it is exactly what I was looking for!!

If Application.Dialogs(xlDialogOpen).Show("Z:\TEMP\*.xls") = False
Then
MsgBox "User Cancelled!"
End If

 
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
Application.Dialogs(xlDialogPrint).Show Luc Microsoft Excel Programming 4 15th Feb 2010 03:24 AM
Re: capturing messagebox OK/cancel event Steve C. Orr [MVP, MCSD] Microsoft ASP .NET 6 7th Sep 2005 03:26 PM
Capturing OS dialogs Steve Koon Microsoft C# .NET 1 26th Aug 2005 06:29 PM
application.dialogs(xldialogsformulafind).show and then some ... Peter Microsoft Excel Programming 1 11th Feb 2005 01:10 AM
xlDialogOpen.Show or Activeworkbook.Path? Mike Echo Microsoft Excel Worksheet Functions 2 29th Jan 2005 09:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:06 PM.