Creating, Writing to and Deleting Text Files

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

goels

Thread Starter
Joined
Sep 30, 2004
Messages
9
Hi all,

I am trying to achieve the following functionality using VBA code:

Create a text file
Store a string in that text file, the string itself being contained in a String variable.
(Then I actually run a batch file using the Shell command which will call that particular string from the text file just created and execute certain functionality)
Delete the created text file

(This whole creation and deletion of text file is actually taking place within a Do Until loop. This is being done as I cannot figure out any direct way to pass parameters to a batch file at the same time that I am executing it, using the Shell command. Thus the text file acts as a workaround to that problem.)

Can anyone please also shed some light on how to read a string stored in a text file from a batch file. I am just hoping that this step itself is not too complicated.

Chow
Goels
 
Joined
Sep 15, 2004
Messages
40
You can pass a string argument to a batch file using:

shell "path to batch.bat " & chr(34) & strArgument & chr(34)

Where the string is stored in a string variable.

To read and write to a text file use:

Code:
Dim fNum as long
fNum=FreeFile
Open "filepath.txt" for Output as fNum
Write fNum, strString
Close fNum
To delete use:

Code:
Kill "path to file.txt"
:)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top