Solved

Need a batch file to update a number of excel files

Posted on 2013-12-14
6
675 Views
Last Modified: 2013-12-15
I need help in creating a batch file that will find and replace a string of texts in a number of excel files that are located in a named folder. I am using Excel 2010 64bit and running a Windows 7 64 bit machine. Is a batch file even the best way to do this? If there is a another way other than a batch file I am open to that too.
0
Comment
Question by:fdbguy
6 Comments
 
LVL 52

Expert Comment

by:Joe Winograd, EE MVE
ID: 39718876
This program's specs are exactly what you're looking for:
http://www.sobolsoft.com/excelreplace/

I ran across this program a while ago and am simply passing it along for your consideration. I have not tried it, so you're on your own to test and evaluate it. Note that it is not free...price is $19.99 USD and they use Digital River for distribution. Regards, Joe
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39718957
If you need to do that often, applying some filtering criteria on the file names to process, maybe even some conditional replaces, then a batch file in PowerShell or VBScript is well suited. You could also use an Excel macro to change other workbooks' content. Neither of those approaches is complicated.

Maybe you should tell some more details, so we can get a better figure of what you are trying to accomplish.
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39719450
Here is a macro that will replace text in all worksheets in all Excel files in a user-specified folder. List the text to replace in vFind. List the corresponding replacements in vReplace. The statements that need to change are commented in the code below, which should be installed in a regular module sheet.
Sub FolderTextReplacer()
Dim ws As Worksheet
Dim wb As Workbook
Dim flPath As String, flName As String
Dim vFind As Variant, vReplace As Variant
Dim i As Long, j As Long, n As Long
vFind = Array("Amalgamated Steelboom, Inc.", "Mammoth Enterprises, LLC")    'List as many strings to find as you like, separated by commas
vReplace = Array("Amalgamated Steelboom, LTD", "Mammoth Enterprises, Inc.") 'List corresponding replacement strings, separated by commas
flPath = Application.GetOpenFilename("Excel files (*.xls*), *xls*", _
        Title:="Pick any file in desired folder, then click 'Open'")
If flPath = "False" Then Exit Sub

n = UBound(vFind)
j = InStrRev(flPath, Application.PathSeparator)
flPath = Left(flPath, j)
flName = Dir(flPath & "*.xls*")

Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
Do Until flName = ""
    Set wb = Workbooks(flName)
    If wb Is Nothing Then
        Set wb = Workbooks.Open(flPath & flName)
        For Each ws In wb.Worksheets
            For i = 0 To n
                ws.Cells.Replace vFind(i), vReplace(i), LookAt:=xlPart, MatchCase:=False
            Next
        Next
        wb.Save
        wb.Close SaveChanges:=False
        Set wb = Nothing
    End If
    flName = Dir
Loop
On Error GoTo 0
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

Open in new window

ReplaceTextAllFilesInFolderQ2831.xlsm
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:fdbguy
ID: 39719970
byundt, That worked like a charm...But what do you mean by "installed in a regular module sheet"? I have no experience in creating or running excel macros. Upon editing what you sent me it opens Visual Basic.
0
 
LVL 81

Expert Comment

by:byundt
ID: 39720004
Macros can be placed in a regular module sheet, such as are named Module1 or Module2. This is what I did in the sample workbook I posted.

Macros can also be placed in the specialized class module sheets associated with each workbook, worksheet or chartsheet. These will have names like ThisWorkbook, Sheet1, Sheet2, Chart1, Chart2, etc. Although I could have put the macro there, good practice suggests not doing so.

Macros are written in Visual Basic for Applications, which is a subset of Visual Basic (i.e. it predates VB.Net). In the right hands, macros are a very powerful tool. Since the VBA language and IDE are furnished free of charge with every copy of Office, Microsoft should be applauded for giving power users the ability to do so much more than would seem possible to the casual observer.

When I post code as the possible solution to an Experts Exchange question, I give the briefest of instructions. Really, just enough to install the code and customize it to suit what I am guessing is the real problem. I'm glad to give more discussion when asked, but competitive pressures (often, the first person to post a working solution gets credit for the Answer) mean that any such discussion will happen after the formula or code has been found to solve the real problem.

Brad
0
 
LVL 52

Expert Comment

by:Joe Winograd, EE MVE
ID: 39720050
Hi Brad,
That is an awesome solution and a terrific piece of code! Great stuff! Regards, Joe
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

773 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