I have added a confirmation dialog to a vbs script (provided by 3rd party) but I do not need to click the “OK” 3 times and would like the confirmation prompt to show only once… In my (limited) knowledge I do not manage to do that, can anybody kindly correct this code?
Set fso = CreateObject("Scripting.FileSystemObject")
a = "C:\Path to file 1\File 1.txt"
b = "C:\Path to file 2\File 2.txt"
RenameItem a, a & ".bak"
RenameItem b, a
RenameItem a & ".bak", b
Sub RenameItem(oldname, newname)
If fso.FileExists(oldname) Or fso.FolderExists(oldname) Then
If fso.FileExists(oldname) Then Set f = fso.GetFile(oldname)
If fso.FolderExists(oldname) Then Set f = fso.GetFolder(oldname)
f.Name = fso.GetFileName(newname)
End If
Msgbox "Files were toggled successfully" & vbNewLine & vbNewLine & "(click the ""OK"" button to exit)"
End Sub
RenameItem()is a sub(routine), i.e. a unit of code which can be reused. Every time you call the sub, it executes everything in it, including theMsgBox.Move this line outside of the sub:
Full Code