View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Cancel option possible while opening a file?

Hi Aiyer,

Try changing:

If MyFile = "" Then


to:

If MyFile = False Then


---
Regards,
Norman



" " wrote in message
...
Hello!

I was trying to open a file as follows, however the user needs to have
a 'cancel' option as well. I.e., if the 'Cancel' button in the pop up
screen is hit, it should exit the macro. I tried the following but it
does'nt work.
==============================================
Sub importfile()

Application.ScreenUpdating = False
Application.DisplayAlerts = False

MyFile = Application.GetOpenFilename("text files,*.txt")

If MyFile = "" Then
Exit Sub
End If

Workbooks.OpenText Filename:=MyFile, _
Origin:=xlWindows, StartRow:=1, _
DataType:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(11, 1), Array(20, 1))

endsub
==============================================

Any suggestions?

Thanks in advance.

Regds,

Arun.
Vtec Corp.


---
Message posted from http://www.ExcelForum.com/