Solved

Works on one computer but not on others

Posted on 2011-02-20
9
255 Views
Last Modified: 2012-05-11
I have a script that works on one computer but when I copied and pasted the folder into a USB and then copied it to the desktop of another computer it keeps saying it can't find the file "Names.xlsx" even though it is in the folder.
Wow.vbs
0
Comment
Question by:Dier02
  • 3
  • 2
  • 2
  • +2
9 Comments
 

Author Comment

by:Dier02
Comment Utility
Would the drive references be a part of the problem? (C:D - the one with issues is on a network and the computer the script works on is a stand-alone.)
WOW-issue.PNG
0
 
LVL 3

Expert Comment

by:sunezapa
Comment Utility
so the user is called rmoul6 on both comouters, and the full path is correct? It look a bit strange with the folder "desktop" both on D: and C: ;-)

it it is only a one-time move you could fix it in the code,
but it may be better to open the excel-file with a relative, and not a absolute path,
 - what is the content of your script, around the failing line number 9?
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
If you do the following from a command prompt on the computer where it fails, what does it show?

DIR "c:\users\rmoul6\desktop\wow project\names.xlsx"

~bp
0
 
LVL 24

Accepted Solution

by:
jimyX earned 450 total points
Comment Utility
You can use the WshSpecialFolders object to get the path to the Desktop/MyDocuments so the top lines in your file will be:

Set objShell = CreateObject("WScript.Shell")

Dim WSHShell, DesktopPath, MyDocumentsPath
Set WSHShell = WScript.CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
MyDocumentsPath = WSHShell.SpecialFolders("MyDocuments")
strNames = objShell.ExpandEnvironmentStrings(DesktopPath & "\WOW Project\Names.xlsx")
strStudents = objShell.ExpandEnvironmentStrings(MyDocumentsPath & "\Student Spelling.xlsx")
strTemplate = objShell.ExpandEnvironmentStrings(DesktopPath & "\WOW Project\WOW-example.xls")

Open in new window

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 50 total points
Comment Utility
The C:\Users\rmoul6 reference is generated by
objShell.ExpandEnvironmentStrings("%USERPROFILE%")

so it should be accurate.  As was suggested by jimyX, maybe the SpecialFolders method will work better.

strNames = objShell.SpecialFolders("Desktop") & "\WOW Project\Names.xlsx")
strStudents = objShell.SpecialFolders("MyDocuments") & "\Student Spelling.xlsx")
strTemplate = objShell.SpecialFolders("Desktop") & "\WOW Project\WOW-example.xls")

Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
The extra brackets should be there....

strNames = objShell.SpecialFolders("Desktop") & "\WOW Project\Names.xlsx"
strStudents = objShell.SpecialFolders("MyDocuments") & "\Student Spelling.xlsx"
strTemplate = objShell.SpecialFolders("Desktop") & "\WOW Project\WOW-example.xls"


Rob.
0
 

Author Comment

by:Dier02
Comment Utility
How does this go into the script below because it comes up with an unterminated string error:

Set objShell = CreateObject("WScript.Shell")

Dim WSHShell, DesktopPath, MyDocumentsPath
Set WSHShell = WScript.CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
MyDocumentsPath = WSHShell.SpecialFolders("MyDocuments")
strNames = objShell.ExpandEnvironmentStrings(DesktopPath & "\WOW Project\Names.xlsx")
strStudents = objShell.ExpandEnvironmentStrings(MyDocumentsPath & "\Student Spelling.xlsx")
strTemplate = objShell.ExpandEnvironmentStrings(DesktopPath & "\WOW Project
Set objExcel = CreateObject("Excel.Application")
Const xlUp = -4162
Const xlPasteAll = -4104
Set objNames = objExcel.Workbooks.Open(strNames, False, False)
Set objTemplate = objExcel.Workbooks.Open(strTemplate, False, False)
objExcel.Visible = True
Set objStudents = objExcel.Workbooks.Add
While objStudents.Sheets.Count > 1
      objExcel.DisplayAlerts = False
      objStudents.Sheets(objStudents.Sheets.Count).Delete
      objExcel.DisplayAlerts = True
Wend
For intRow = 2 To objNames.Sheets(1).Cells(65536, "B").End(xlUp).Row
      strName = objNames.Sheets(1).Cells(intRow, "B").Value
      If objStudents.Sheets(1).Name = "Sheet1" Then
            objStudents.Sheets(1).Name = strName
      Else
            objStudents.Sheets.Add , objStudents.Sheets(objStudents.Sheets.Count)
            objStudents.Sheets(objStudents.Sheets.Count).Name = strName
      End If
      objTemplate.Sheets(1).Cells.Copy
      objStudents.Sheets(strName).Cells.PasteSpecial(xlPasteAll)
Next
objNames.Close
objStudents.SaveAs strStudents
objStudents.Close
objExcel.Quit
0
 
LVL 24

Expert Comment

by:jimyX
Comment Utility
My mistake I corrected in my test file but when copied your original forgot to correct the parenthesis:
Set objShell = CreateObject("WScript.Shell")

Dim WSHShell, DesktopPath, MyDocumentsPath
Set WSHShell = WScript.CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
MyDocumentsPath = WSHShell.SpecialFolders("MyDocuments")
strNames = objShell.ExpandEnvironmentStrings(DesktopPath & "\WOW Project\Names.xlsx")
strStudents = objShell.ExpandEnvironmentStrings(MyDocumentsPath & "\Student Spelling.xlsx")
strTemplate = objShell.ExpandEnvironmentStrings(DesktopPath & "\WOW Project\WOW-example.xls")
Set objExcel = CreateObject("Excel.Application")
Const xlUp = -4162
Const xlPasteAll = -4104
Set objNames = objExcel.Workbooks.Open(strNames, False, False)
Set objTemplate = objExcel.Workbooks.Open(strTemplate, False, False)
objExcel.Visible = True
Set objStudents = objExcel.Workbooks.Add
While objStudents.Sheets.Count > 1
      objExcel.DisplayAlerts = False
      objStudents.Sheets(objStudents.Sheets.Count).Delete
      objExcel.DisplayAlerts = True
Wend
For intRow = 2 To objNames.Sheets(1).Cells(65536, "B").End(xlUp).Row
      strName = objNames.Sheets(1).Cells(intRow, "B").Value
      If objStudents.Sheets(1).Name = "Sheet1" Then
            objStudents.Sheets(1).Name = strName
      Else
            objStudents.Sheets.Add , objStudents.Sheets(objStudents.Sheets.Count)
            objStudents.Sheets(objStudents.Sheets.Count).Name = strName
      End If
      objTemplate.Sheets(1).Cells.Copy
      objStudents.Sheets(strName).Cells.PasteSpecial(xlPasteAll)
Next
objNames.Close
objStudents.SaveAs strStudents
objStudents.Close
objExcel.Quit

Open in new window

0
 

Author Closing Comment

by:Dier02
Comment Utility
Thanks JimyX - worked a treat! Thanks Rob as well.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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 …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

728 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

9 Experts available now in Live!

Get 1:1 Help Now