Solved

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

Posted on 2008-10-15
12
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 22720602
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
ID: 22720662
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
ID: 22721024
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sal21
ID: 22721030
... or when i click on "X" on the form
0
 

Author Comment

by:sal21
ID: 22721041
... or when i click ctrl pause on the form
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22723192
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
ID: 22728852
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
ID: 22728857
sorry...
doc1.doc
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 22730024
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
ID: 22730181
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
ID: 22730926
No, that's the limitations of using plain vbscript...sorry...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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