troubleshooting Question

VBS Script Fails to run

Avatar of Thomas Grassi
Thomas GrassiFlag for United States of America asked on
Microsoft ExcelShell ScriptingVB Script
4 Comments1 Solution455 ViewsLast Modified:
Windows 2003 R2 Standard Member Server SP2
Excel 2010 SP1

a expert on here helped me with this script
from a command prompt  

c:\cscript c:\util\csvmerge.vbs

this error happens

csvmerge.vbs(23,17) Microsoft Excel Cannot rename a sheet to the same name as another sheet a referenced object library or a workbook referenced by visual basic

This same script ran great on my Windows 7 Pro computer where it was developed.

This Server runs a Inventory program that runs a script that generates 20 .cvs2 files

This script is suppose to place all the csv2 files into one spreadsheet and each on an individual sheet.

One Note I am having another issue installing Office SP2 on this server tring to fix that now
Dont know if this may be the issue.


  Dim FromWorkbook
    Dim ToWorkbook
    Dim fso
    Dim CurrentFolder
    Dim objExcel
    Dim boolFirst
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set CurrentFolder = fso.GetFolder("D:\inventory")
    Set objExcel = CreateObject("Excel.Application")
    ProcessFolder CurrentFolder

Sub ProcessFolder(ByVal Folder)
   Dim Files
   Set Files = Folder.Files
   Dim File
    For Each File In Files
        If right(File.Name,3) = "csv" Then
            If not boolfirst Then
                Set ToWorkbook = objExcel.Workbooks.Open(File)
                boolFirst = true
            Else
                Set FromWorkbook = objExcel.Workbooks.Open(File)
                FromWorkbook.Sheets(1).Copy ToWorkbook.Sheets(1)
                FromWorkbook.Close
            End If
        End If
    Next
    ToWorkbook.SaveAs "d:\inventory\test.xlsx",51
    ToWorkbook.Close False
    Set ToWorkbook = Nothing
End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros