SteveGregory
Structural
- Jul 18, 2006
- 554
I have the code for 2 buttons that I would like to add a new feature. I would like each button to delete a small txt file and write a new txt file to the same folder that the spreadsheet was launched from.
Here are the files:
1. "Ram Elements IN USE.txt" with one line of text that contains the active cell's contents.
2. "Ram Elements EXIT.txt" with one line of text that contains the active cell's contents.
Here is my current code for Button 1:
Private Sub CommandButton1_Click()
Dim RetVal
ActiveCell = Now() & " " & Environ("username")
' Delete "Ram Elements EXIT.txt" and write new "Ram Elements IN USE.txt"
ActiveWorkbook.Save
ActiveCell.Offset(0, 1).Select
RetVal = Shell("C:\RamElem.cmd", 1)
End Sub
The code for Button 2 is similar:
Private Sub CommandButton2_Click()
ActiveCell = Now() & " " & Environ("username")
' Delete "Ram Elements IN USE.txt" and write new "Ram Elements EXIT.txt"
ActiveCell.Offset(1, -1).Select
ActiveWorkbook.Close SaveChanges:=True
End Sub
As you guessed, I don't have a clue how to make it work other than how to write a comment line. The spreadsheet and the current buttons work well in our environment. Adding and deleting the text files will allow us to see at a glance if anyone and who is using the 1 copy of the program that is licensed to us.
Here are the files:
1. "Ram Elements IN USE.txt" with one line of text that contains the active cell's contents.
2. "Ram Elements EXIT.txt" with one line of text that contains the active cell's contents.
Here is my current code for Button 1:
Private Sub CommandButton1_Click()
Dim RetVal
ActiveCell = Now() & " " & Environ("username")
' Delete "Ram Elements EXIT.txt" and write new "Ram Elements IN USE.txt"
ActiveWorkbook.Save
ActiveCell.Offset(0, 1).Select
RetVal = Shell("C:\RamElem.cmd", 1)
End Sub
The code for Button 2 is similar:
Private Sub CommandButton2_Click()
ActiveCell = Now() & " " & Environ("username")
' Delete "Ram Elements IN USE.txt" and write new "Ram Elements EXIT.txt"
ActiveCell.Offset(1, -1).Select
ActiveWorkbook.Close SaveChanges:=True
End Sub
As you guessed, I don't have a clue how to make it work other than how to write a comment line. The spreadsheet and the current buttons work well in our environment. Adding and deleting the text files will allow us to see at a glance if anyone and who is using the 1 copy of the program that is licensed to us.