View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Macro search text boxes

The following code will look at every workbook in a folder, search
every text box (ActiveX control textbox) on every worksheet, and
replace FindText with ReplaceText. Change the lines marked with
'<<<<< to the values you need.

Sub AAA()
Dim Folder As String
Dim FileName As String
Dim WB As Workbook
Dim WS As Worksheet
Dim OLEObj As OLEObject
Dim FindText As String
Dim ReplaceText As String
Dim S As String

Folder = "C:\Test" '<<<<< CHANGE AS NEEDED
FindText = "abc" '<<<<< CHANGE AS NEEDED
ReplaceText = "def" '<<<<< CHANGE AS NEEDED
ChDrive Folder
ChDir Folder
FileName = Dir("*.xls", vbNormal)
Do Until FileName = vbNullString
Set WB = Workbooks.Open(FileName)
For Each WS In WB.Worksheets
For Each OLEObj In WS.OLEObjects
If TypeOf OLEObj.Object Is MSForms.TextBox Then
S = Replace(OLEObj.Object.Text, _
FindText, ReplaceText)
OLEObj.Object.Text = S
End If
Next OLEObj
Next WS
WB.Close savechanges:=True
FileName = Dir()
Loop
End Sub



Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




On Fri, 12 Feb 2010 15:43:01 -0800, Mike H
wrote:

Is there any way for a macro to search or iterate through text boxes?
I need to find and replace text that might be within text boxes
(and not just in cells), for hundreds of spreadsheets.
I don't know what excel or windows versions, but probably 2003 on XP.