Ooops...my bad...I got it working now
Thanks so much! Here is an
example of my code with comments:
Public Sub UserForm_Activate()
' The BatchSched form and code is used to remotely schedule tasks on single
or multiple servers
' The servernames are obtained from a local file called
C:\scripts\selection.txt
' The selection.txt file is created from another macro where users view a
spreadsheet and select
' the server(s) they wish to perform the task on
' Upon loading of this module, the user inputs the remote batch file and
start time that
' they wish to schedule on the remote server(s)
Dim inputcmd As String
'variable that will be populated from the txt_rmtcmd object on form
Dim st_hr As String
'Start Hour variable that will be populated from the txt_start_hr object
on form
Dim st_min As String
'Start Minute variable that will be populated from the txt_start_min
object on form
cmd_execute.Enabled = False
'disables the EXECUTE button on the form by default until user enables
the chk_confirm check box.
End Sub
Private Sub chk_Confirm_Change()
' This is a failsafe feature to require the user to check the confirmation
box before enabling
' the Execute command button
If chk_confirm.Value = True Then
cmd_execute.Enabled = True
Else: cmd_execute.Enabled = False
End If
End Sub
Private Sub cmd_execute_Click()
'cmd_execute is a command button on a form that is clicked to excute the
commands assuming
' other inputs have been performed
Dim X As Long
Dim FileNum As Long
Dim TotalFile As String
Dim Records() As String
Dim cmdstring As String
'This is a variable that I will use to construct my shell command in the loop
inputcmd = txt_rmtcmd.Text
'Gets a path and batch filename, from user input, to execute on a remote
server
'It uses the txt_rmtcmd object (textbox) on the form
st_hr = txt_start_hour.Text
'Gets the hour of the time, from user input, to execute the command in
24hour format
'It uses the txt_start_hour object (textbox) on the form
st_min = txt_start_min.Text
'Gets the minute of the time, from user input, to execute the command in
24hour format
'It uses the txt_start_min object (textbox) on the form
FileNum = FreeFile
Open "c:\scripts\selection.txt" For Binary As #FileNum
TotalFile = Space(LOF(FileNum))
Get #FileNum, , TotalFile
Close #FileNum
' Now that the entire file is now contained in the TotalFile
' variable, let's split the file into individual lines
Records = Split(TotalFile, vbCrLf)
' Okay, now process each line from the file
For X = 0 To UBound(Records)
cmdstring = "cmd.exe /c AT " + "\\" + Records(X) + " " + st_hr + ":" +
st_min + " " + inputcmd
'assembly of a shell command to schedule a remote task for each server
(Records(X))
'for the desired time (st_hr+":"st_min) using the command input by user
(inputcmd)
Shell (cmdstring), 1
' The cmdstring is then sent to command shell for processing
'
' Process each line from the file as needed... they are in Records(X)
'
Next
' Repeats the process for each line (server) listed in the selection.txt
file until the end of file
End Sub
Private Sub cmd_exit_Click()
Unload BatchSched
'closes the form when the Exit button is clicked
End Sub