Thread: Open TXT file
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
T Lavedas T Lavedas is offline
external usenet poster
 
Posts: 38
Default Open TXT file

On May 16, 1:12 pm, Ric0999 wrote:
Hi,

How do i call and open a txt file (Notepade) using macro?

Tks in advance.


What do you want to do with the content? Parse it into cells (rows/
columns)? Us it in a macro as data? Reformat it and write it out to
another file? or what?

To have the text data parsed into the rows and columns of a
spreadsheet you may want to invoke the Data Import function or you
might just want to use the Workbook.OpenText to access it. If it
needs to be parsed and placed in cells, you might want to use the VBA
Open and Read functions.

Knowing something about what the data looks like and what you want to
do with it would go a long way towards providing the most beneficial
answer.

For example, I just opened Excel and recorded a macro to access a
space and comma delimited set of data in a text file and I got
something like this ...

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 5/16/2008 by Tom Lavedas
'
ChDir "C:\Documents and Settings\username\My Documents\"
Workbooks.OpenText Filename:= _
"C:\Documents and Settings\username\My Documents\MyData.txt" _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, _
Tab:=True, Semicolon:=False, _
Comma:=True, Space:=True, Other:=False, _
FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6,
1)),_
TrailingMinusNumbers:=True
End Sub

That might serve you or it might not. There's just no way to tell
without more info.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/