Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-12-2019, 11:41 PM
guwic guwic is offline Need  help to replace a word in word file (macro) Windows 10 Need  help to replace a word in word file (macro) Office 2013
Novice
Need  help to replace a word in word file (macro)
 
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 Need  help to replace a word in word file (macro) Windows 7 64bit Need  help to replace a word in word file (macro) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
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
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need  help to replace a word in word file (macro) Find and Replace Numbers Macro VBA in Microsoft Word Yotem189 Word VBA 3 09-20-2018 05:55 AM
Need  help to replace a word in word file (macro) 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  help to replace a word in word file (macro) 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
Need  help to replace a word in word file (macro) How to replace this word file using wildcard zhangzujin361 Word 1 01-18-2014 08:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:45 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft