[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Need a batch file to update a number of excel files

Posted on 2013-12-14
6
Medium Priority
?
1,007 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
[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
6 Comments
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
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 71

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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 56

Expert Comment

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

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

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…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

650 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