Solved

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

Posted on 2008-10-15
12
338 Views
Last Modified: 2011-10-19
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
0
Comment
Question by:sal21
  • 6
  • 5
12 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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

0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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

0
 

Author Comment

by:sal21
Comment Utility
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....(?!)
0
 

Author Comment

by:sal21
Comment Utility
... or when i click on "X" on the form
0
 

Author Comment

by:sal21
Comment Utility
... or when i click ctrl pause on the form
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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

0
 

Author Comment

by:sal21
Comment Utility
Hi sirbounty...
with new version have the error in img attached...
To be sure attach here a your tersted version, tks.
Pizza for you!
0
 

Author Comment

by:sal21
Comment Utility
sorry...
doc1.doc
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
Sorry about that - missed the parenthesis.
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 strResp = "" Then Exit Sub

  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

0
 

Author Comment

by:sal21
Comment Utility
WORK NOW!
But instead to use the standard input type tetxbox code, is possible to show a good and elegant form?
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
No, that's the limitations of using plain vbscript...sorry...
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now