Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 05-12-2019, 11:41 PM
guwic guwic is offline Windows 10 Office 2013
Novice
 
Join Date: May 2019
Posts: 1
guwic is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 05-13-2019, 12:23 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,392
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


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


All times are GMT -7. The time now is 10:13 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft