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

Hi all,
does anyone have a hint on how I can load a tab delimited
file into a worksheet using VBA code??? (also how to save
a worksheet into a tab del text file) I need to process a
large number of files and would like to automate the
loading and saving procedure.

Thanks a lot.
Mathias
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default import text file

turn on the macro recorder

file=Open, select the file and walk through the text import wizard.


when the file is in, turn off the macro recorder.

I get:
Workbooks.OpenText Filename:="C:\tabtext2.txt", Origin:=437, StartRow:=1
_
, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2,
1), _
Array(3, 1)), TrailingMinusNumbers:=True

You can replace "C:\tabtext2.txt " with a variable like fname and use

Dim fName as String
fName = application.GetOpenFileName(FileFilter:="Text Files (*.txt),*.txt")
if lcase(fName) < "false" then
Workbooks.OpenText Filename:=fName, Origin:=437, StartRow:=1 _
, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2,
1), _
Array(3, 1)), TrailingMinusNumbers:=True
End If


you could turn on the macro recorder and save a file - for example I get:
ActiveWorkbook.SaveAs Filename:="C:\tabtext2.txt", FileFormat:=xlText, _
CreateBackup:=False

Now you can use GetSaveAsFileName

Dim fName as String
fName = Application.GetSaveAsFilename()
if lcase(fName) < "false" then
ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=xlText, _
CreateBackup:=False
ActiveWorkbook.close SaveChanges:=False
End if

--
Regards,
Tom Ogilvy

"Mathias" wrote in message
...
Hi all,
does anyone have a hint on how I can load a tab delimited
file into a worksheet using VBA code??? (also how to save
a worksheet into a tab del text file) I need to process a
large number of files and would like to automate the
loading and saving procedure.

Thanks a lot.
Mathias



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default import text file

Thanks a lot!!!
-----Original Message-----
turn on the macro recorder

file=Open, select the file and walk through the text

import wizard.


when the file is in, turn off the macro recorder.

I get:
Workbooks.OpenText Filename:="C:\tabtext2.txt",

Origin:=437, StartRow:=1
_
, DataType:=xlDelimited,

TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True,

Semicolon:=False,
Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array

(Array(1, 1), Array(2,
1), _
Array(3, 1)), TrailingMinusNumbers:=True

You can replace "C:\tabtext2.txt " with a variable like

fname and use

Dim fName as String
fName = application.GetOpenFileName(FileFilter:="Text

Files (*.txt),*.txt")
if lcase(fName) < "false" then
Workbooks.OpenText Filename:=fName, Origin:=437,

StartRow:=1 _
, DataType:=xlDelimited,

TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True,

Semicolon:=False,
Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array

(Array(1, 1), Array(2,
1), _
Array(3, 1)), TrailingMinusNumbers:=True
End If


you could turn on the macro recorder and save a file -

for example I get:
ActiveWorkbook.SaveAs Filename:="C:\tabtext2.txt",

FileFormat:=xlText, _
CreateBackup:=False

Now you can use GetSaveAsFileName

Dim fName as String
fName = Application.GetSaveAsFilename()
if lcase(fName) < "false" then
ActiveWorkbook.SaveAs Filename:=fName,

FileFormat:=xlText, _
CreateBackup:=False
ActiveWorkbook.close SaveChanges:=False
End if

--
Regards,
Tom Ogilvy

"Mathias" wrote in

message
...
Hi all,
does anyone have a hint on how I can load a tab

delimited
file into a worksheet using VBA code??? (also how to

save
a worksheet into a tab del text file) I need to process

a
large number of files and would like to automate the
loading and saving procedure.

Thanks a lot.
Mathias



.

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
Can I import text file of cash flow to excel file then use formula Bumpa Excel Discussion (Misc queries) 2 May 28th 10 04:22 PM
Set Defaults in File Import of a Text File Dkline Excel Worksheet Functions 2 January 28th 08 06:20 PM
Would Like to Automate Batch File Creation and Text FIle Import socrtwo Excel Discussion (Misc queries) 2 August 18th 06 03:54 PM
Import text file into excel with preset file layout, delimeters VBA meldrape Excel Programming 7 June 15th 04 08:31 PM
Get External Data, Import Text File, File name problem Scott Riddle Excel Programming 1 July 11th 03 05:40 PM


All times are GMT +1. The time now is 04:46 PM.

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

About Us

"It's about Microsoft Excel"