Link to home
Start Free TrialLog in
Avatar of salvatore imparato
salvatore imparatoFlag for Italy

asked on

hot to assign to a icon a vbs script (500+500 pts)

Admit have a dir on server: \\myserver\mydir\
In this dir have five file excel:
test_8501.xls  
test_8502.xls  
test_8503.xls  
test_8504.xls  
test_8505.xls

how to make a vbs script file:

if the user press on vbs script icon, appear a form with a text box where the user can insert a code, similar 8501.
With a button on this form, start a code to copy a xls file from server dir with the last 4 charachter 8501 and paste the excel file in c:\mydir withouit popup yes/no for overwrite the existis file with the same name of current file

hope understnd me.

Tks to all
Avatar of sirbounty
sirbounty
Flag of United States of America image

I think I understand...
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
strResp = InputBox ("Enter the code number","Input needed")
 
If objFSO.FileExists ("\\myserver\mydir\test_" & strResp & ".xls") Then
  objFSO.CopyFile "\\myserver\mydir\test_" & strResp & ".xls", "C:\mydir\", True
End If

Open in new window

This version will allow a loop if an invalid code is entered...
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
CopyFile()
 
Set objFSO = Nothing
wscript.quit
 
Sub CopyFile()
 strResp = InputBox ("Enter the code number","Input needed", "8501")
 
  If objFSO.FileExists ("\\myserver\mydir\test_" & strResp & ".xls") Then
    objFSO.CopyFile "\\myserver\mydir\test_" & strResp & ".xls", "C:\mydir\", True
  Else
    Msgbox "Sorry, that file does not exist.  Please try again...", vbOkOnly, "Invalid File Code"
    CopyFile()
  End If
End Sub

Open in new window

Avatar of salvatore imparato

ASKER

Hi sirbounty...
Yuo have understand perfect my Napolitan/English (i'm live in Napoli:-) the code work very well:
But when i click on cancel button the code go in loop and reapper the form....(?!)
... or when i click on "X" on the form
... or when i click ctrl pause on the form
I understand...try this:
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
CopyFile()
 
Set objFSO = Nothing
wscript.quit
 
Sub CopyFile()
 strResp = InputBox ("Enter the code number","Input needed", "8501")
 
  If objFSO.FileExists ("\\myserver\mydir\test_" & strResp & ".xls") Then
    objFSO.CopyFile "\\myserver\mydir\test_" & strResp & ".xls", "C:\mydir\", True
  Else
    strResult = Msgbox "Sorry, that file does not exist.  Please try again...", vbRetryCancel, "Invalid File Code"
    If strResult = vbCancel Then Exit Sub
    CopyFile()
  End If
End Sub

Open in new window

Hi sirbounty...
with new version have the error in img attached...
To be sure attach here a your tersted version, tks.
Pizza for you!
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
WORK NOW!
But instead to use the standard input type tetxbox code, is possible to show a good and elegant form?
No, that's the limitations of using plain vbscript...sorry...