Solved

Need a batch file to update a number of excel files

Posted on 2013-12-14
6
627 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 68

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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,…
By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

20 Experts available now in Live!

Get 1:1 Help Now