Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Canceling a read file function


I have a macro where the user is required to select a file to open. This
is done via the Windows Open File dialog box. If they elect to "cancel"
and not open the file, I get an error. I know there must be some coding
I can put into my macro to trap this and just exit the macro if this
happens.

Thanks
Mike


--
mwc0914
------------------------------------------------------------------------
mwc0914's Profile: http://www.excelforum.com/member.php...o&userid=24130
View this thread: http://www.excelforum.com/showthread...hreadid=552286

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Canceling a read file function

On Error GoTo Cancel
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Canceling a read file function

Sorry I forgot to paste the line:

CommonDialog1.CancelError = True

befo

On Error GoTo Cancel

"mwc0914" wrote:


I have a macro where the user is required to select a file to open. This
is done via the Windows Open File dialog box. If they elect to "cancel"
and not open the file, I get an error. I know there must be some coding
I can put into my macro to trap this and just exit the macro if this
happens.

Thanks
Mike


--
mwc0914
------------------------------------------------------------------------
mwc0914's Profile: http://www.excelforum.com/member.php...o&userid=24130
View this thread: http://www.excelforum.com/showthread...hreadid=552286


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Canceling a read file function

hi Mike

Use GetOpenFilename

Sub test()
Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = ThisWorkbook.Path
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName < False Then
Set wb = Workbooks.Open(FName)
MsgBox "your code"
wb.Close
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub



--
Regards Ron De Bruin
http://www.rondebruin.nl



"mwc0914" wrote in message
...

I have a macro where the user is required to select a file to open. This
is done via the Windows Open File dialog box. If they elect to "cancel"
and not open the file, I get an error. I know there must be some coding
I can put into my macro to trap this and just exit the macro if this
happens.

Thanks
Mike


--
mwc0914
------------------------------------------------------------------------
mwc0914's Profile: http://www.excelforum.com/member.php...o&userid=24130
View this thread: http://www.excelforum.com/showthread...hreadid=552286



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Canceling a read file function


Tired it but am getting False.xls not defined error. My code is...



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Canceling a read file function

Application.GetOpenFilename, nice! I didn't know about that function. I was
surprised I didn't need to use quotes he

If FName < "False" Then


"Ron de Bruin" wrote:

hi Mike

Use GetOpenFilename

Sub test()
Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = ThisWorkbook.Path
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName < False Then
Set wb = Workbooks.Open(FName)
MsgBox "your code"
wb.Close
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub



--
Regards Ron De Bruin
http://www.rondebruin.nl



"mwc0914" wrote in message
...

I have a macro where the user is required to select a file to open. This
is done via the Windows Open File dialog box. If they elect to "cancel"
and not open the file, I get an error. I know there must be some coding
I can put into my macro to trap this and just exit the macro if this
happens.

Thanks
Mike


--
mwc0914
------------------------------------------------------------------------
mwc0914's Profile: http://www.excelforum.com/member.php...o&userid=24130
View this thread: http://www.excelforum.com/showthread...hreadid=552286




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Canceling a read file function

Not use "False"

You get problems when you run the code on a Dutch machine or other language

See Stephen's site
http://www.oaltd.co.uk/ExcelProgRef/Default.htm

Click on "International Issues"


--
Regards Ron De Bruin
http://www.rondebruin.nl



"Charlie" wrote in message ...
Application.GetOpenFilename, nice! I didn't know about that function. I was
surprised I didn't need to use quotes he

If FName < "False" Then


"Ron de Bruin" wrote:

hi Mike

Use GetOpenFilename

Sub test()
Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = ThisWorkbook.Path
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName < False Then
Set wb = Workbooks.Open(FName)
MsgBox "your code"
wb.Close
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub



--
Regards Ron De Bruin
http://www.rondebruin.nl



"mwc0914" wrote in message
...

I have a macro where the user is required to select a file to open. This
is done via the Windows Open File dialog box. If they elect to "cancel"
and not open the file, I get an error. I know there must be some coding
I can put into my macro to trap this and just exit the macro if this
happens.

Thanks
Mike


--
mwc0914
------------------------------------------------------------------------
mwc0914's Profile: http://www.excelforum.com/member.php...o&userid=24130
View this thread: http://www.excelforum.com/showthread...hreadid=552286






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Canceling a read file function


I got it working with the following code...

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
Self canceling checkboxes Glenn Excel Discussion (Misc queries) 3 October 28th 08 03:11 PM
I have a read only xl file, I need it to be read and write drama queen Excel Discussion (Misc queries) 3 July 1st 06 12:25 AM
How can a file be converted from Read-Only to Read/Write Jim in Apopka Excel Discussion (Misc queries) 2 November 19th 05 04:59 PM
Canceling a print job Dan Scholler Excel Programming 2 August 9th 04 06:24 PM
Canceling a UserForm Eric W. Excel Programming 1 August 26th 03 06:56 PM


All times are GMT +1. The time now is 04:58 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"