Guidance with creating a bespoke .txt

K

Krayten

Hi All,

Hoping that someone might be able to give me a push in the right
direction here...please!

I need to have xlvba create a simple two line .cmd file, the contents of
which will be determined via several userforms that the user will have
had to fill in.

I have no problem getting the .cmd to then run in the background using
the Shell commands - it's just the creation of the file ( which is
essentially just a .txt anyway ) and the inputting of the two or so
lines of data.

I would ideally like to create the .cmd then fill in the two lines, then
delete the .cmd at the end, if this is possible.

I would be very grateful for any direction.

Rgds

======
Stuart
 
T

Tom Ogilvy

the following pseudo code should get you going.

Sub Doit()
Dim sStr as String
Dim LineofText As String
Dim rw as Long
rw = 0
Open "C:\CMDFILE\MyFile.cmd" For Output As #1
Print #1, "Echo Off"
print #1, "Dir *.* > c:\newfile.txt"
'Close the file
Close #1
Shell "C:\cmdfile\myfild.cmd"
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
On Error Resume Next
Kill "C:\CMDFILE\MyFile.cmd"
On Error goto 0
End Sub
 
K

krayten

Fantastic - I only needed to modify your code a tiny bit to get the job
done precisely
as I needed -- very grateful to you Tom!

One ? If I may...

The macro failed at the Shell command line.
I am having trouble opening .txt files with the Shell command.

Should it be:

Shell ( C:\Windows\Notepad.exe C:\testfile.txt) , 0

or

Shell "C:\testfile.txt", 0

I'm using xlvba 2003

Thanks again,

Stuart
 
K

krayten

Uh Got it, it should be

Shell ("C:Windows\Notepade.exe C:\testfile.txt")

Thanks anyway!

Stuart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top