macro interruption: help!!!

M

Mario

Hi everybody

I created a macro who open a textfile and divides it in columns

The macro doesn't give the possibility of choosing the file to open. (it
always opens the file I choose when I registerd it)

I would like it gives the possibility to choose the file and then it started
again... how can I do?

Thi is the macro:
Workbooks.OpenText Filename:= _
"C:\Documents and
Settings\b0\Documenti\Attivita\PmiSolution\clienti\GM\2004\NSCADFAG.scadfor"
_
, Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:= _
Array(Array(0, 1), Array(31, 1), Array(39, 9), Array(46, 4),
Array(54, 1), Array(72, 1), _
Array(73, 4), Array(82, 1), Array(114, 1))
End Sub

Thanks
Mario
 
D

Dave Peterson

One way:

Option Explicit
Sub testme()

Dim myFileName As Variant

myFileName = Application.GetOpenFilename(filefilter:="Text Files, *.Txt", _
Title:="Pick a File")

If myFileName = False Then
MsgBox "Ok, try later" 'user hit cancel
Exit Sub
End If

Workbooks.OpenText Filename:=myFileName '....rest of recorded code here!

End Sub
 
S

Stefan Hägglund [MSFT]

Hi Mario,

Try this code:

Sub OpenTextFile()
Dim MyFile As Variant
' Ask the user for the file name to open.
MyFile = Application.GetOpenFilename
' Check for the Cancel button.
If MyFile = False Then Exit Sub
' Open the Text file with the OpenText method.
Workbooks.OpenText Filename:=MyFile, Origin:=xlWindows, _
StartRow:=1, DataType:=:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(31, 1), Array(39, 9), Array(46, 4), Array(54, 1),
Array(72, 1), _
Array(73, 4), Array(82, 1), Array(114, 1))
End Sub

Best regards

Stefan Hägglund
Microsoft
 
M

mario milani

Thank you Dave your macro works perfectly...
It's the first I use "news group" I'm sorry if I haven't familiarity
with it. Sorry for my english too.
Mario
 
M

mario milani

Thank you Stefan your macro works perfectly...
It's the first time I use "news group" I'm sorry if I haven't
familiarity with it. Sorry for my english too.
Mario
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

macro interruption 3
macro interruption: help..... 1
Open File 2
Macro Error 6
Can you help me solve! 1
Modify Macro Code Depending on Excel Version 11
Cannot open text workbook 1
Text Import Wizard 1

Top