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

Hi,

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

Tks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
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/
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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.


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
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Setting up and Configuration of Excel 0 April 23rd 09 08:53 PM
In Excel - Use Windows Explorer instead of File Open to open file KymY Excel Discussion (Misc queries) 1 August 5th 06 09:59 PM
Open a file do a macro ( made) and open next succesive file SVTman74 Excel Programming 5 April 21st 06 10:14 PM
Open File or Switch Between Windows if File is Open Ricky Pang Excel Programming 2 July 8th 05 05:51 AM
Open File or Switch Between Windows if File is Open Ricky Pang Excel Programming 0 July 2nd 05 08:41 PM


All times are GMT +1. The time now is 08:37 AM.

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"