Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Fixed length file import??

I have a fixed length file, thats 700 characters long. Each week i
have to go in and manually import the file, and tell excel where the
fields are. The fields are the same length everytime. Is there a way
to open a new excel sheet and have it automatically import the
information? I have been looking at some scripts, but i have no idea
where to put them.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Fixed length file import??

Turn the macro recorder on

Open the file and go through the text import wizard.

Turn off the macro recorder.

Look at the recorded code. This contains the specificiations you gave.

You can add code to prompt you for a file name and feed it into the first
argument of the OPENTEXT method.

then to import the file, you just run the code.

If you need help on modifying the recorded code to accept a dynamic file
name, post back with the recorded code.

some informationon getting started with macros at David McRitchie's site
http://www.mvps.org/dmcritchie/excel/getstarted.htm
--
Regards,
Tom Ogilvy

"Trey" wrote in message
oups.com...
I have a fixed length file, thats 700 characters long. Each week i
have to go in and manually import the file, and tell excel where the
fields are. The fields are the same length everytime. Is there a way
to open a new excel sheet and have it automatically import the
information? I have been looking at some scripts, but i have no idea
where to put them.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Fixed length file import??

Tom,

Thanks for the info, its working great so far. I would like to make it
accept a dynamic file name. Here is the code.

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;p:\My Documents\Clients\Campus Partners\020406.txt",
Destination:=Range _
("A1"))
.Name = "020406"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 2, 2, 2, 2, 1, 1, 1, 2, 1,
1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1 _
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(1, 5, 30, 9, 25, 25, 25, 18,
9, 1, 1, 10, 10, 9, 5, 9, 2 _
, 2, 1, 2, 1, 1, 10, 10, 10, 6, 10, 10, 10, 7, 1, 7, 7, 7, 7,
3, 3, 3, 3, 3, 3, 10, 1, 7, 1, 1, 6, 10, 10, 10, 10 _
, 5, 5, 1, 5, 5, 10, 10, 10, 10, 10, 7, 10, 7, 1, 1, 1, 2, 3,
30, 25, 25, 25, 18, 9, 1, 1, 10)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub


Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Fixed length file import??

Sub GetFile()
Dim sName as String
sName = Application.GetOpenFilename( _
FileFilter:="Text Files (*.txt),*.txt")
If sName = "False" then exit sub
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & sName, Destination:=Range("A1"))
.Name = "020406"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 2, 2, 2, 2, _
1, 1, 1, 2, 1,1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(1, 5, 30, _
9, 25, 25, 25, 18, 9, 1, 1, 10, 10, 9, 5, 9, 2, _
2, 1, 2, 1, 1, 10, 10, 10, 6, 10, 10, 10, 7, 1, _
7, 7, 7, 7, 3, 3, 3, 3, 3, 3, 10, 1, 7, 1, 1, 6, _
10, 10, 10, 10, 5, 5, 1, 5, 5, 10, 10, 10, 10, _
10, 7, 10, 7, 1, 1, 1, 2, 3, 30, 25, 25, 25, 18, _
9, 1, 1, 10)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

--
Regards,
Tom Ogilvy

"Trey" wrote in message
oups.com...
Tom,

Thanks for the info, its working great so far. I would like to make it
accept a dynamic file name. Here is the code.

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;p:\My Documents\Clients\Campus Partners\020406.txt",
Destination:=Range _
("A1"))
.Name = "020406"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 2, 2, 2, 2, 1, 1, 1, 2, 1,
1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1 _
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(1, 5, 30, 9, 25, 25, 25, 18,
9, 1, 1, 10, 10, 9, 5, 9, 2 _
, 2, 1, 2, 1, 1, 10, 10, 10, 6, 10, 10, 10, 7, 1, 7, 7, 7, 7,
3, 3, 3, 3, 3, 3, 10, 1, 7, 1, 1, 6, 10, 10, 10, 10 _
, 5, 5, 1, 5, 5, 10, 10, 10, 10, 10, 7, 10, 7, 1, 1, 1, 2, 3,
30, 25, 25, 25, 18, 9, 1, 1, 10)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub


Thanks



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 length file Steve S[_2_] Excel Discussion (Misc queries) 2 March 13th 07 04:12 PM
Fixed length text file Eric Excel Discussion (Misc queries) 1 July 12th 06 10:02 PM
Export file to CSV delimited with fixed field length Plucky Duck Excel Discussion (Misc queries) 2 May 28th 05 11:01 PM
How do I export an excel file as fixed length records iainjh Excel Discussion (Misc queries) 2 March 3rd 05 05:59 PM
2 Qs: grab net page, and import as fixed length format Keith R[_3_] Excel Programming 2 December 12th 03 08:18 PM


All times are GMT +1. The time now is 04:10 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"