fixed width import

M

maryj

I need to import a fixed width text file on a daily basis. The format will
always be the same but the title is different. The text file will always be
in the same folder on my computer. I have tried recording a macro using the
import wizard, but it hard codes the file name. How can I add something to
prompt me for the file name?

Thanks for your help!
 
J

JW

I need to import a fixed width text file on a daily basis. The format will
always be the same but the title is different. The text file will always be
in the same folder on my computer. I have tried recording a macro using the
import wizard, but it hard codes the file name. How can I add something to
prompt me for the file name?

Thanks for your help!

Try incorporating Application.GetOpenFilename. Set a string variable
equal to that and then replace the hard coded filename with the
variable name.
 
D

Dave Peterson

Option Explicit
Sub Testme01()

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
 
M

maryj

Thanks Dave! Works perfect!
--
maryj


Dave Peterson said:
Option Explicit
Sub Testme01()

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
 

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

Top