ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Open TXT file (https://www.excelbanter.com/excel-programming/411064-open-txt-file.html)

Ric0999

Open TXT file
 
Hi,

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

Tks in advance.

T Lavedas

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/

Chip Pearson

Open TXT file
 
If all you want to do is open it in NotePad, you can use the Shell command.

Shell "Notepad.exe ""C:\ZZZ.txt""""

watch the quote marks.

If you want to open an arbitrary file in the program designated for that
file type, use code like the following:

Public Declare Function FindExecutable Lib "shell32.dll" Alias
"FindExecutableA" ( _
ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String) As Long


Sub AAA()
Dim R As Long
Dim ExeName As String
Dim FName As String
FName = "C:\Book1.xls"
ExeName = String$(255, vbNullChar)
R = FindExecutable(FName, vbNullString, ExeName)
If R 0 Then
ExeName = Left(ExeName, R)
Shell ExeName & " """ & FName & """"
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





"Ric0999" wrote in message
...
Hi,

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

Tks in advance.




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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com