Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
dan dan is offline
external usenet poster
 
Posts: 866
Default Importing a file(s)

Worked great. Understood the process but now I want to import a second file
after the end of the first file.

Same file twice, fisrt in a Delimited format - to extraxct the header info
(fisrt 20 lines). But then I want to open the file again and extract the data
in a Fixed Width format undernear the header infor above.

The rest of the file will vary in length, from 1000 to 30,000.

Thanks



Dave Peterson wrote:

I'd just import it to a new workbook, then copy what I want and paste to where I
want it. Then close the new workbook.

Option Explicit
Sub testme01()

Dim DestCell As Range
Dim TextWks As Worksheet

Set DestCell = ActiveSheet.Range("a10")

Workbooks.OpenText Filename:="C:\yourfilenamehere.txt", _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1)

Set TextWks = ActiveSheet

TextWks.Range("1:35").Copy _
Destination:=DestCell

TextWks.Parent.Close savechanges:=False

End Sub

Record a macro when you do the importing and replace my Opentext line with
yours.


Dan wrote:

I want to import a file into excel but I want to limit the number of lines
that is imported. For example the file may be 150 lines but I only want the
first 35. I want to automate this task.

Also I want the to import the data at a specific line in excel - not A1,
somewhere around A10.

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
dan dan is offline
external usenet poster
 
Posts: 866
Default Importing a file(s)

OK. Here is what I have to achieve this task. This was created by recoding a
macro then tweaking the file. It can probably be cleaned up some more.

Now I need to accomplish two additonal tasks:
1. Have the user select the file;

myFileName = Application.GetOpenFilename(filefilter:="Text or ASC Files,
*.txt; *.asc", _
Title:="Select the Data File")

2. A stand alone macro so it can be run by selecting an icon on the desk top.

Thanks

Sub Import_Files()
'
' Import_Files Macro
'

Workbooks.OpenText Filename:= _
"C:\myfile.txt" _
, Origin:=437, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array( _
Array(0, 1), Array(9, 1), Array(12, 1), Array(18, 1), Array(22, 1),
Array(24, 1), Array(26, _
1), Array(34, 1), Array(35, 1), Array(37, 1), Array(40, 1),
Array(43, 1), Array(46, 1), _
Array(49, 1), Array(52, 1), Array(55, 1), Array(58, 1)),
TrailingMinusNumbers:=True
Rows("6:6").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("Book1").Activate
Range("A6").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Columns("A:AB").Select
Columns("A:AB").EntireColumn.AutoFit
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A6").Select
Windows("myfile.txt").Activate
Range("D637").Select
ActiveWindow.Close
Workbooks.OpenText Filename:= _
"C:\myfile.txt" _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Rows("1:5").Select
Selection.Copy
Application.CutCopyMode = False
Selection.Copy
Windows("Book1").Activate
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Application.CutCopyMode = False
Windows("myfile.txt").Activate
Range("B9").Select
ActiveWindow.Close
End Sub

"Dan" wrote:

Worked great. Understood the process but now I want to import a second file
after the end of the first file.

Same file twice, fisrt in a Delimited format - to extraxct the header info
(fisrt 20 lines). But then I want to open the file again and extract the data
in a Fixed Width format undernear the header infor above.

The rest of the file will vary in length, from 1000 to 30,000.

Thanks



Dave Peterson wrote:

I'd just import it to a new workbook, then copy what I want and paste to where I
want it. Then close the new workbook.

Option Explicit
Sub testme01()

Dim DestCell As Range
Dim TextWks As Worksheet

Set DestCell = ActiveSheet.Range("a10")

Workbooks.OpenText Filename:="C:\yourfilenamehere.txt", _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1)

Set TextWks = ActiveSheet

TextWks.Range("1:35").Copy _
Destination:=DestCell

TextWks.Parent.Close savechanges:=False

End Sub

Record a macro when you do the importing and replace my Opentext line with
yours.


Dan wrote:

I want to import a file into excel but I want to limit the number of lines
that is imported. For example the file may be 150 lines but I only want the
first 35. I want to automate this task.

Also I want the to import the data at a specific line in excel - not A1,
somewhere around A10.

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
Importing Files into Excel [email protected] Excel Discussion (Misc queries) 2 June 27th 06 06:43 PM
importing multiple text files into the same worksheet Mike D Excel Discussion (Misc queries) 4 July 15th 05 10:39 AM
Importing multiple Text files into Excel 2003 JMA Excel Discussion (Misc queries) 5 May 5th 05 09:48 PM
importing multiple text files URGENT!!! HELP tasha Excel Worksheet Functions 0 December 19th 04 04:26 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 10:06 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"