ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   fixed width import (https://www.excelbanter.com/excel-programming/411915-fixed-width-import.html)

maryj

fixed width import
 
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!
--
maryj

JW[_2_]

fixed width import
 
On Jun 2, 1:14*pm, maryj wrote:
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!
--
maryj


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

Dave Peterson

fixed width import
 
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

maryj wrote:

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!
--
maryj


--

Dave Peterson

maryj

fixed width import
 
Thanks Dave! Works perfect!
--
maryj


"Dave Peterson" wrote:

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

maryj wrote:

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!
--
maryj


--

Dave Peterson



All times are GMT +1. The time now is 06:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com