Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing multiple text files to worksheets


I have 3 files in a the folder C:\SOA\

1.A0001-D
2.A0001-H
3.A0001-F

Files Ending with D contains Details, with H contains Header info & F
with Footer info.
A0001 is the account number

I will need to import all three files into 3 worksheets in one
workbook.

Question is how can I use the account no & path from the first file
imported to import the next two files?

Any help is greatly appreciated! :)

My recorded macro below:


Sub ImportSOA()
FNameD = Application.GetOpenFilename(FileFilter:="All Files (*.*),
*.*", Title:="Please select the Details file.")

If FNameD = False Then
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Application.DisplayAlerts = False
Workbooks.OpenText Filename:=FNameD, _
Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:= _
Array(Array(0, 2), Array(7, 2), Array(37, 2), Array(45, 2),
Array(46, 2), Array(49, 2), _
Array(52, 2), Array(61, 2), Array(69, 1), Array(73, 4),
Array(81, 1), Array(92, 1), Array( _
101, 1), Array(112, 1), Array(123, 1), Array(134, 1),
Array(144, 1))
End If

Application.ScreenUpdating = False

ActiveSheet.Name = "DETAIL"

Sheets.Add Type:="Worksheet"
With ActiveSheet.QueryTables.Add(Connection:= _
* "TEXT;"C:\SOA\A0001-F", Destination:=Range("A2"))
..Name = "Footer"
..FieldNames = True
..RowNumbers = False
..FillAdjacentFormulas = False
..PreserveFormatting = True
..RefreshOnFileOpen = False
..RefreshStyle = xlInsertDeleteCells
..SavePassword = False
..SaveData = True
..AdjustColumnWidth = True
..RefreshPeriod = 0
..TextFilePromptOnRefresh = False
..TextFilePlatform = xlWindows
..TextFileStartRow = 1
..TextFileParseType = xlFixedWidth
..TextFileTextQualifier = xlTextQualifierDoubleQuote
..TextFileConsecutiveDelimiter = False
..TextFileTabDelimiter = True
..TextFileSemicolonDelimiter = False
..TextFileCommaDelimiter = False
..TextFileSpaceDelimiter = False
..TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1)
..TextFileFixedColumnWidths = Array(13, 13, 13, 13, 13, 13, 14,
12)
..Refresh BackgroundQuery:=False
End With

Sheets.Add Type:="Worksheet"
With ActiveSheet.QueryTables.Add(Connection:= _
* "TEXT;"C:\SOA\A0001-H", Destination:=Range("A2"))
..Name = "Header"
..FieldNames = True
..RowNumbers = False
..FillAdjacentFormulas = False
..PreserveFormatting = True
..RefreshOnFileOpen = False
..RefreshStyle = xlInsertDeleteCells
..SavePassword = False
..SaveData = True
..AdjustColumnWidth = True
..RefreshPeriod = 0
..TextFilePromptOnRefresh = False
..TextFilePlatform = xlWindows
..TextFileStartRow = 1
..TextFileParseType = xlFixedWidth
..TextFileTextQualifier = xlTextQualifierDoubleQuote
..TextFileConsecutiveDelimiter = False
..TextFileTabDelimiter = True
..TextFileSemicolonDelimiter = False
..TextFileCommaDelimiter = False
..TextFileSpaceDelimiter = False
..TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 2, 4, 2, 1,
1)
..TextFileFixedColumnWidths = Array(47, 30, 30, 30, 30, 3, 5,
13, 2, 20)
..Refresh BackgroundQuery:=False
End With

Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub


--
josnah
------------------------------------------------------------------------
josnah's Profile: http://www.excelforum.com/member.php...fo&userid=6334
View this thread: http://www.excelforum.com/showthread...hreadid=548074

  #2   Report Post  
Posted to microsoft.public.excel.programming
ADG ADG is offline
external usenet poster
 
Posts: 76
Default Importing multiple text files to worksheets

Hi Josnah

I think your file names can be calculated with the below

FNameF = Left$(FNameD, Len(FNameD) - 1) & "F"
FNameH = Left$(FNameD, Len(FNameD) - 1) & "H"
--
Tony Green


"josnah" wrote:


I have 3 files in a the folder C:\SOA\

1.A0001-D
2.A0001-H
3.A0001-F

Files Ending with D contains Details, with H contains Header info & F
with Footer info.
A0001 is the account number

I will need to import all three files into 3 worksheets in one
workbook.

Question is how can I use the account no & path from the first file
imported to import the next two files?

Any help is greatly appreciated! :)

My recorded macro below:


Sub ImportSOA()
FNameD = Application.GetOpenFilename(FileFilter:="All Files (*.*),
*.*", Title:="Please select the Details file.")

If FNameD = False Then
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Application.DisplayAlerts = False
Workbooks.OpenText Filename:=FNameD, _
Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:= _
Array(Array(0, 2), Array(7, 2), Array(37, 2), Array(45, 2),
Array(46, 2), Array(49, 2), _
Array(52, 2), Array(61, 2), Array(69, 1), Array(73, 4),
Array(81, 1), Array(92, 1), Array( _
101, 1), Array(112, 1), Array(123, 1), Array(134, 1),
Array(144, 1))
End If

Application.ScreenUpdating = False

ActiveSheet.Name = "DETAIL"

Sheets.Add Type:="Worksheet"
With ActiveSheet.QueryTables.Add(Connection:= _
* "TEXT;"C:\SOA\A0001-F", Destination:=Range("A2"))
.Name = "Footer"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(13, 13, 13, 13, 13, 13, 14,
12)
.Refresh BackgroundQuery:=False
End With

Sheets.Add Type:="Worksheet"
With ActiveSheet.QueryTables.Add(Connection:= _
* "TEXT;"C:\SOA\A0001-H", Destination:=Range("A2"))
.Name = "Header"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 2, 4, 2, 1,
1)
.TextFileFixedColumnWidths = Array(47, 30, 30, 30, 30, 3, 5,
13, 2, 20)
.Refresh BackgroundQuery:=False
End With

Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub


--
josnah
------------------------------------------------------------------------
josnah's Profile: http://www.excelforum.com/member.php...fo&userid=6334
View this thread: http://www.excelforum.com/showthread...hreadid=548074


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing multiple text files to worksheets


Thanks very much Tony!
Somehow it didn't work with *-Len(FNameD) - 1-* but with Len*-(FNameD)
- 2-*!

Now I am wondering how I can make this macro loop and choose the next
account?


--
josnah
------------------------------------------------------------------------
josnah's Profile: http://www.excelforum.com/member.php...fo&userid=6334
View this thread: http://www.excelforum.com/showthread...hreadid=548074

  #4   Report Post  
Posted to microsoft.public.excel.programming
ADG ADG is offline
external usenet poster
 
Posts: 76
Default Importing multiple text files to worksheets

Hi

Try looking a Scripting.FileSystemObject in the help text this has a number
of tools that will help you work with files and directories.

--
Tony Green


"josnah" wrote:


Thanks very much Tony!
Somehow it didn't work with *-Len(FNameD) - 1-* but with Len*-(FNameD)
- 2-*!

Now I am wondering how I can make this macro loop and choose the next
account?


--
josnah
------------------------------------------------------------------------
josnah's Profile: http://www.excelforum.com/member.php...fo&userid=6334
View this thread: http://www.excelforum.com/showthread...hreadid=548074


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing multiple text files to worksheets


Hi Tony,

I have figured out why it didn't work with Len(FNameD) - 1 cos the
FNameD ends with a "." and so will need to -2 chars instead of just 1.

Thanks again! Appreciate your help!


--
josnah
------------------------------------------------------------------------
josnah's Profile: http://www.excelforum.com/member.php...fo&userid=6334
View this thread: http://www.excelforum.com/showthread...hreadid=548074



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
Importing multiple Text files into Excel [email protected] Excel Programming 2 April 9th 06 01:35 PM
Importing multiple Text files into Excel [email protected] Excel Programming 0 April 8th 06 05:21 PM
Importing multiple Text files into Excel [email protected] Excel Programming 0 April 8th 06 05:21 PM
Importing from multiple text files tmort[_15_] Excel Programming 1 November 8th 05 01:42 PM
importing multiple text files??? tashayu Excel Discussion (Misc queries) 0 December 19th 04 02:43 PM


All times are GMT +1. The time now is 12:01 AM.

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"