Cancel option possible while opening a file?

  • Thread starter Thread starter aiyer
  • Start date Start date
A

aiyer

Hello!

I was trying to open a file as follows, however the user needs to hav
a 'cancel' option as well. I.e., if the 'Cancel' button in the pop u
screen is hit, it should exit the macro. I tried the following but i
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
 
Back
Top