User Tools

Site Tools


operating_systems:microsoft:vsreplace

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
operating_systems:microsoft:vsreplace [2013/05/14 15:16] sbolayoperating_systems:microsoft:vsreplace [2013/05/14 15:29] (current) sbolay
Line 7: Line 7:
 'Last update: may 14, 2013 'Last update: may 14, 2013
  
 +'Inspired from http://word.tips.net/T003783_Changing_Information_in_Multiple_Documents.html
 Public Sub VSReplace() Public Sub VSReplace()
     Dim Directory As String     Dim Directory As String
     Dim FType As String     Dim FType As String
     Dim FName As String     Dim FName As String
 +    
 +    FType = "*.doc"
 +    FLocation = "C:\VS"
          
     Dim colFiles As New Collection     Dim colFiles As New Collection
-    RecursiveDir colFiles, "C:\VS""*.doc", True +    RecursiveDir colFiles, FLocation FType, True
- +
-    FType = "*.doc" +
  
     Dim vFile As Variant     Dim vFile As Variant
Line 33: Line 34:
 End Sub End Sub
  
 +'From http://www.ammara.com/access_image_faq/recursive_folder_search.html
 Public Function RecursiveDir(colFiles As Collection, _ Public Function RecursiveDir(colFiles As Collection, _
                              strFolder As String, _                              strFolder As String, _
Line 70: Line 72:
 End Function End Function
  
 +'From http://www.ammara.com/access_image_faq/recursive_folder_search.html
 Public Function TrailingSlash(strFolder As String) As String Public Function TrailingSlash(strFolder As String) As String
     If Len(strFolder) > 0 Then     If Len(strFolder) > 0 Then
Line 80: Line 83:
 End Function End Function
  
 +'Modified from http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm
 Public Function FindAndReplace() Public Function FindAndReplace()
  
 Dim myStoryRange As Range Dim myStoryRange As Range
 +
 +TFind_FR = "Département de l'éducation, de la culture et du sport"
 +TReplace_FR = "Département de la formation et de la sécurité"
 +
 +TFind_DE = "Departement für Erziehung, Kultur und Sport"
 +TReplace_DE = "Departement für Bildung und Sicherheit"
  
 'First search the main document using the Selection and replace french text 'First search the main document using the Selection and replace french text
  With Selection.Find  With Selection.Find
-    .Text = "DÈpartement de l'Èducation, de la culture et du sport" +    .Text = TFind_FR 
-    .Replacement.Text = "DÈpartement de la formation et de la sÈcuritÈ"+    .Replacement.Text = TReplace_FR
     .Forward = True     .Forward = True
     .Wrap = wdFindContinue     .Wrap = wdFindContinue
Line 101: Line 111:
  'Then search the main document using the Selection and replace german text  'Then search the main document using the Selection and replace german text
  With Selection.Find  With Selection.Find
-    .Text = "Departement f¸r Erziehung, Kultur und Sport" +    .Text = TFind_DE 
-    .Replacement.Text = "Departement f¸r Bildung und Sicherheit"+    .Replacement.Text = TReplace_DE
     .Forward = True     .Forward = True
     .Wrap = wdFindContinue     .Wrap = wdFindContinue
Line 118: Line 128:
    If myStoryRange.StoryType <> wdMainTextStory Then    If myStoryRange.StoryType <> wdMainTextStory Then
         With myStoryRange.Find         With myStoryRange.Find
-            .Text = "DÈpartement de l'Èducation, de la culture et du sport" +            .Text = TFind_FR 
-            .Replacement.Text = "DÈpartement de la formation et de la sÈcuritÈ"+            .Replacement.Text = TReplace_FR
             .Wrap = wdFindContinue             .Wrap = wdFindContinue
             .Execute Replace:=wdReplaceAll             .Execute Replace:=wdReplaceAll
         End With         End With
         With myStoryRange.Find         With myStoryRange.Find
-            .Text = "Departement f¸r Erziehung, Kultur und Sport" +            .Text = TFind_DE 
-            .Replacement.Text = "Departement f¸r Bildung und Sicherheit"+            .Replacement.Text = TReplace_DE
             .Wrap = wdFindContinue             .Wrap = wdFindContinue
             .Execute Replace:=wdReplaceAll             .Execute Replace:=wdReplaceAll
Line 132: Line 142:
            Set myStoryRange = myStoryRange.NextStoryRange            Set myStoryRange = myStoryRange.NextStoryRange
             With myStoryRange.Find             With myStoryRange.Find
-                .Text = "DÈpartement de l'Èducation, de la culture et du sport" +                .Text = TFind_FR 
-                .Replacement.Text = "DÈpartement de la formation et de la sÈcuritÈ"+                .Replacement.Text = TReplace_FR
                 .Wrap = wdFindContinue                 .Wrap = wdFindContinue
                 .Execute Replace:=wdReplaceAll                 .Execute Replace:=wdReplaceAll
             End With             End With
             With myStoryRange.Find             With myStoryRange.Find
-                .Text = "Departement f¸r Erziehung, Kultur und Sport" +                .Text = TFind_DE 
-                .Replacement.Text = "Departement f¸r Bildung und Sicherheit"+                .Replacement.Text = TReplace_DE
                 .Wrap = wdFindContinue                 .Wrap = wdFindContinue
                 .Execute Replace:=wdReplaceAll                 .Execute Replace:=wdReplaceAll
operating_systems/microsoft/vsreplace.1368544593.txt.gz · Last modified: 2013/05/14 15:16 by sbolay