VBA/Excel/Access/Word/Forms/Replace

Материал из VB Эксперт
Версия от 15:48, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Replace information in all sheets of the workbook

   <source lang="vb">

Sub ChgInfo()

   Dim Sht As Worksheet
   For Each Sht In Worksheets
       Sht.Cells.Replace What:="old", Replacement:="new", LookAt:=xlPart, MatchCase:=False
   Next

End Sub

</source>
   
  


Replacing with the Replace Method

   <source lang="vb">

Sub replace()

   ActiveSheet.Columns("B").Replace What:="Sales", _
       Replacement:="Sales & Marketing", SearchOrder:=xlByColumns, _
       MatchCase:=True

End Sub

</source>
   
  


Using Replace to Replace Formatting

   <source lang="vb">

Sub ReplaceFormats()

   " set formatting to look for 
   With Application.FindFormat 
       .Font.Bold = True 
       .Font.Size = 11 
   End With 
   " set formatting that should be applied instead 
   With Application.ReplaceFormat 
       .Font.Bold = False 
       .Font.Italic = True 
       .Font.Size = 8 
   End With 
   ActiveSheet.Cells.Replace What:="", Replacement:="", _ 
       SearchFormat:=True, ReplaceFormat:=True 

End Sub

</source>