Solved

Works on one computer but not on others

Posted on 2011-02-20
9
259 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
[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
  • 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 55

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
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!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

689 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