Guidance with creating a bespoke .txt
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 |
Guidance with creating a bespoke .txt
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 -- Regards, Tom Ogilvy "Krayten" wrote in message om... 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 |
Guidance with creating a bespoke .txt
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 |
Guidance with creating a bespoke .txt
Uh Got it, it should be
Shell ("C:Windows\Notepade.exe C:\testfile.txt") Thanks anyway! Stuart |
All times are GMT +1. The time now is 03:31 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com