Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default 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.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixed Width Text Import Settings Bryan Excel Discussion (Misc queries) 4 July 8th 08 12:15 AM
Repeatable Fixed Width Import donnie darko Excel Discussion (Misc queries) 9 December 6th 06 06:47 PM
HOW DO YOU SET THE DEFAULT FIXED COLOMN WIDTH ON THE EXCEL IMPORT Robert Belote Excel Discussion (Misc queries) 0 May 5th 06 08:33 PM
import fixed width text file OE Excel Programming 1 June 20th 05 02:56 PM
Import *.asc file into excel fixed width Hartsell Excel Programming 1 February 24th 04 08:15 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"