ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   For each workbook (https://www.excelbanter.com/excel-programming/344647-each-workbook.html)

Ctech[_36_]

For each workbook
 

I need two versions of my code below, which now replaces a text in all
sheets of an open workbook.

WHAT I NEED IN ADDITION TO THIS IS:

1. Replace in all open workbooks,
2. Replace in all workbooks in specified folder....



THIS IS MY CODE:

Private Sub cmd_OK_Click()
Dim Morg
Dim Mto

Morg = Lbud.TextBox_org
Mto = Lbud.TextBox_to



Dim Sht As Worksheet



For Each Sht In Worksheets
Sht.Cells.Replace What:=Morg, _
Replacement:=Mto, LookAt:=xlPart, MatchCase:=False
Next





Unload Lbud
End Sub


--
Ctech
------------------------------------------------------------------------
Ctech's Profile: http://www.excelforum.com/member.php...o&userid=27745
View this thread: http://www.excelforum.com/showthread...hreadid=481942


Carlos[_6_]

For each workbook
 
Hi Ctech

see below

WHAT I NEED IN ADDITION TO THIS IS:

1. Replace in all open workbooks,


try this

sub openWorkBooks()
Dim wn As Window

For Each wn In Windows
wn.Activate
call cmd_OK_Click ' run your rotine
Next
end sub



2. Replace in all workbooks in specified folder....


Sub folder()

Dim nFiles As Long
Dim Filename As String

' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
'select all or some excel files
.AllowMultiSelect = True
.Show

' Display paths of each file selected
For nFiles = 1 To .SelectedItems.Count

Filename = .SelectedItems(nFiles)
Workbooks.Open Filename ' open wookbooks

Call cmd_OK_Click 'run your rotine

Application.DisplayAlerts = False
ActiveWorkbook.Close True 'save and close
Application.DisplayAlerts = True

Next

End With

End Sub


THIS IS MY CODE:

Private Sub cmd_OK_Click()
Dim Morg
Dim Mto

Morg = Lbud.TextBox_org
Mto = Lbud.TextBox_to



Dim Sht As Worksheet



For Each Sht In Worksheets
Sht.Cells.Replace What:=Morg, _
Replacement:=Mto, LookAt:=xlPart, MatchCase:=False
Next





Unload Lbud
End Sub


--
Ctech
------------------------------------------------------------------------
Ctech's Profile:
http://www.excelforum.com/member.php...o&userid=27745
View this thread: http://www.excelforum.com/showthread...hreadid=481942





All times are GMT +1. The time now is 02:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com