Solved

Works on one computer but not on others

Posted on 2011-02-20
9
257 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
ID: 34939857
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
ID: 34939896
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 53

Expert Comment

by:Bill Prew
ID: 34939912
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 24

Accepted Solution

by:
jimyX earned 450 total points
ID: 34939998
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
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 50 total points
ID: 34940140
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
ID: 34940148
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
ID: 34940636
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
ID: 34940664
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
ID: 34940674
Thanks JimyX - worked a treat! Thanks Rob as well.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
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 on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

828 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