#1
|
|||
|
|||
Need help to replace a word in word file (macro)
With help a macro i want to substitute all names written with upcase letters with a word with letters following the first in lowcase letters. Here i my code to do this, sometimes it doesn't work, I cannot figure out why, can someone help?
Part of the code, the bold word to replace has been identified for i =..... to ... (With ActiveDocument.Words(i)) (skip junk, find net bold name..) MsgBox = Left(.Text, 1) + LCase(Mid(.Text, 2)) ' changing text works! .Text = Left(.Text, 1) + LCase(Mid(.Text, 2)) ' but not this! (End With) Next Here i part of my word-document before and after running the macro. Replacing with a fixed string (like "ABC") works (but not very helpful). Of course I've tried a lot of variations without success. Any idea about what is wrong will be welcome. Before: Tabell II A1 ELLEN MARGARETA DOROTEA LINDSTRÖM (se tab II) *1863-08-03 i Visby, död 1922 och begr i Pittsburg, USA. Tabell II A2 IVAN EUGÈNE ANATOLE LINDSTRÖM (se tab II) *1865-02-19 i Visby, död 1927 i Visby, begr i familje¬graven i Visby. Student-ex 1885 i Visby. Genomgick Gymnastiska Central¬institutet i Stockholm 1885-87. Anst såsom sjukgymnast vid Frans Lind¬ströms After: Tabell II A1 ELLEN MARGARETA DOROTEA Lindström (se tab II) *1863-08-03 i Visby, död 1922 och begr i Pittsburg, USA. Tabell II A2 IVAN EUGÈNE ANATOLE Lindström (se tab II) *1865-02-19 i Visby, död 1927 i Visby, begr i familje¬graven i Visby. Student-ex 1885 i Visby. Genomgick Gymnastiska Central¬institutet i Stockholm 1885-87. |
#2
|
||||
|
||||
It's not apparent how much content you're trying to convert. You might start with something like:
Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "<[A-Z]{3,}>" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .Find.Found .Text = StrConv(.Text, vbProperCase) .Collapse wdCollapseEnd .Find.Execute Loop End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Find and Replace Numbers Macro VBA in Microsoft Word | Yotem189 | Word VBA | 3 | 09-20-2018 05:55 AM |
Macro to check the existence of a word docx file and create a new word file with specific content. | staicumihai | Word VBA | 14 | 11-15-2016 01:42 AM |
Need Macro for Find and Replace, Inserting logo in Ms-Word. | Aswinraj | Word VBA | 1 | 06-05-2016 04:33 PM |
Macro to put 1 word of a MS Word file in 1 cell of a Word or Excel Table | Singh_Edm | Word VBA | 6 | 11-13-2015 08:48 PM |
How to replace this word file using wildcard | zhangzujin361 | Word | 1 | 01-18-2014 08:02 PM |