Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-27-2018, 04:50 PM
BobT BobT is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 10 replacing the full name of elements by their respective symbol, in a long MS Word text. Office 2016
Novice
replacing the full name of elements by their respective symbol, in a long MS Word text.
 
Join Date: Jul 2018
Posts: 9
BobT is on a distinguished road
Default replacing the full name of elements by their respective symbol, in a long MS Word text.

Could you help me with a macro to replace the full name of elements by their respective symbol, in a long MS Word text. For example:


"Actinium" replaced by "Ac"
"Aluminum" replaced by "Al"
"Americium" replaced by "Am"
"Antimony" replaced by "Sb"
"Argon" replaced by "Ar"
"Arsenic" replaced by "As"
"Astatine" replaced by "At"
"Barium" replaced by "Ba"

Note: There is no " " in the text, before and after.
Thank you
Reply With Quote
  #2  
Old 07-27-2018, 04:59 PM
Charles Kenyon Charles Kenyon is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 10 replacing the full name of elements by their respective symbol, in a long MS Word text. Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

I could do it, and so could you.
Simply record such a macro.
Reply With Quote
  #3  
Old 07-27-2018, 06:32 PM
macropod's Avatar
macropod macropod is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 7 64bit replacing the full name of elements by their respective symbol, in a long MS Word text. 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

Quote:
Originally Posted by Charles Kenyon View Post
I could do it, and so could you.
Simply record such a macro.
Not particularly helpful...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 07-27-2018, 06:33 PM
macropod's Avatar
macropod macropod is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 7 64bit replacing the full name of elements by their respective symbol, in a long MS Word text. 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

Try the following macro (which would be impossible to record):
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrFnd As String, StrRep As String, i As Long
StrFnd = StrFnd & "|Hydrogen|Helium|Lithium|Beryllium|Boron|Carbon|Nitrogen|Oxygen" & _
  "|Fluorine|Neon|Sodium|Magnesium|Aluminium|Silicon|Phosphorus|Sulphur|Chlorine|Argon" & _
  "|Potassium|Calcium|Scandium|Titanium|Vanadium|Chromium|Manganese|Iron|Cobalt|Nickel" & _
  "|Copper|Zinc|Gallium|Germanium|Arsenic|Selenium|Bromine|Krypton|Rubidium|Strontium" & _
  "|Yttrium|Zirconium|Niobium|Molybdenum|Technetium|Ruthenium|Rhodium|Palladium|Silver" & _
  "|Cadmium|Indium|Tin|Antimony|Tellurium|Iodine|Xenon|Caesium|Barium|Lanthanum|Cerium" & _
  "|Praseodymium|Neodymium|Promethium|Samarium|Europium|Gadolinium|Terbium|Dysprosium" & _
  "|Holmium|Erbium|Thulium|Ytterbium|Lutetium|Hafnium|Tantalum|Tungsten|Rhenium|Osmium" & _
  "|Iridium|Platinum|Gold|Mercury|Thallium|Lead|Bismuth|Polonium|Astatine|Radon|Francium" & _
  "|Radium|Actinium|Thorium|Protactinium|Uranium|Neptunium|Plutonium|Americium|Curium" & _
  "|Berkelium|Californium|Einsteinium|Fermium|Mendelevium|Nobelium|Lawrencium|Rutherfordium" & _
  "|Dubnium|Seaborgium|Bohrium|Hassium|Meitnerium|Darmstadtium|Roentgenium|Copernicium" & _
  "|Nihonium|Flerovium|Moscovium|Livermorium|Tennesine|Oganesson"
StrRep = "|H|He|Li|Be|B|C|N|O|F|Ne|Na|Mg|Al|Si|P|S|Cl|Ar|K|Ca|Sc|Ti|V|Cr|Mn|Fe|Co|Ni|Cu|Zn" & _
  "|Ga|Ge|As|Se|Br|Kr|Rb|Sr|Y|Zr|Nb|Mo|Tc|Ru|Rh|Pd|Ag|Cd|In|Sn|Sb|Te|I|Xe|Cs|Ba|La|Ce|Pr|Nd" & _
  "|Pm|Sm|Eu|Gd|Tb|Dy|Ho|Er|Tm|Yb|Lu|Hf|Ta|W|Re|Os|Ir|Pt|Au|Hg|Tl|Pb|Bi|Po|At|Rn|Fr|Ra|Ac" & _
  "|Th|Pa|U|Np|Pu|Am|Cm|Bk|Cf|Es|Fm|Md|No|Lr|Rf|Db|Sg|Bh|Hs|Mt|Ds|Rg|Cn|Nh|Fl|Mc|Lv|Ts|Og"
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Forward = True
  .Wrap = wdFindContinue
  .MatchCase = True
  .MatchWholeWord = True
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  For i = 1 To UBound(Split(StrFnd, "|"))
    .Text = Split(StrFnd, "|")(i)
    .Replacement.Text = Split(StrRep, "|")(i)
    .Execute Replace:=wdReplaceAll
  Next
End With
Application.ScreenUpdating = True
End Sub
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
For Mac macro installation & usage instructions, see: https://wordmvp.com/Mac/InstallMacro.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-27-2018, 07:18 PM
Charles Kenyon Charles Kenyon is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 10 replacing the full name of elements by their respective symbol, in a long MS Word text. Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by macropod View Post
Not particularly helpful...

I don't happen to have a periodic table handy?
Also, you are much better at writing macros than am I.



My help would have been to record a macro. It would have worked as well as yours but would not have been nearly as elegant.
I felt that if that would work, saying so is helpful.
Reply With Quote
  #6  
Old 07-27-2018, 10:15 PM
macropod's Avatar
macropod macropod is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 7 64bit replacing the full name of elements by their respective symbol, in a long MS Word text. 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

Quote:
Originally Posted by Charles Kenyon View Post
I don't happen to have a periodic table handy?
Neither did I, but finding one online was a simple-enough task. Suggesting someone record a macro for doing a Find/Replace on 118 elements is a bit much and would result in truly bloated code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 07-29-2018, 08:52 AM
BobT BobT is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 10 replacing the full name of elements by their respective symbol, in a long MS Word text. Office 2016
Novice
replacing the full name of elements by their respective symbol, in a long MS Word text.
 
Join Date: Jul 2018
Posts: 9
BobT is on a distinguished road
Default

Thank you, Paul. It works fine. Would it be possible to add this condition to it: "only original words like Hydrogen, Helium, Lithium, etc., are to be changed".
Best,
Bob
Reply With Quote
  #8  
Old 07-29-2018, 09:00 AM
BobT BobT is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 10 replacing the full name of elements by their respective symbol, in a long MS Word text. Office 2016
Novice
replacing the full name of elements by their respective symbol, in a long MS Word text.
 
Join Date: Jul 2018
Posts: 9
BobT is on a distinguished road
Default

Hi Charles, you're not wrong, if you could do it I could probably do it also. Macropod's talent and kindness inspire me and I decided to learn how to code in VBX and create macros.
Regards,
Bob
Reply With Quote
  #9  
Old 07-29-2018, 02:16 PM
macropod's Avatar
macropod macropod is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 7 64bit replacing the full name of elements by their respective symbol, in a long MS Word text. 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

Quote:
Originally Posted by BobT View Post
Would it be possible to add this condition to it: "only original words like Hydrogen, Helium, Lithium, etc., are to be changed".
I don't know what you mean by that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 07-29-2018, 03:06 PM
BobT BobT is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 10 replacing the full name of elements by their respective symbol, in a long MS Word text. Office 2016
Novice
replacing the full name of elements by their respective symbol, in a long MS Word text.
 
Join Date: Jul 2018
Posts: 9
BobT is on a distinguished road
Default

In the text of my document, I would like to keep the full name of the elements--Hydrogen, Helium, Lithium, etc., but in the footnotes, I would like to use the abbreviations instead.
Your macro changes indiscriminately all full names for their corresponding abbreviation, whether they appear in the body of my document or in the footnotes.
Best,
Bob
Reply With Quote
  #11  
Old 07-29-2018, 03:15 PM
macropod's Avatar
macropod macropod is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 7 64bit replacing the full name of elements by their respective symbol, in a long MS Word text. 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

There is nothing indiscriminate about the macro. Your request said nothing about footnotes, so the macro doesn't process them. If you wanted to process footnotes instead of the document body, you should have said so. To process footnotes, change:
With ActiveDocument.Range.Find
to:
With ActiveDocument.StoryRanges(wdFootnotesStory).Find
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 07-29-2018, 05:20 PM
BobT BobT is offline replacing the full name of elements by their respective symbol, in a long MS Word text. Windows 10 replacing the full name of elements by their respective symbol, in a long MS Word text. Office 2016
Novice
replacing the full name of elements by their respective symbol, in a long MS Word text.
 
Join Date: Jul 2018
Posts: 9
BobT is on a distinguished road
Default

You're right. In my initial request, I had not realized that such request could have been included at once. Thank you again, Paul. You saved me hours of manual work, with the inherent mistake potential.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
replacing the full name of elements by their respective symbol, in a long MS Word text. How to always open microsoft word with full text justification ArchanRC Word 2 06-01-2018 03:51 PM
replacing the full name of elements by their respective symbol, in a long MS Word text. turn footnotes and their respective superscripts into normal text GEORGEJUNGCOCAINE Word VBA 2 02-27-2018 10:01 PM
turn footnotes and their respective superscripts into normal unlinkable text GEORGEJUNGCOCAINE Word 1 02-27-2018 05:47 PM
How to adapt a text pasted from PDF to the full width of a microsoft word page Alessio Word 2 01-13-2018 03:35 PM
replacing the full name of elements by their respective symbol, in a long MS Word text. Finding and Replacing a word with text copied to clip board spc94 Word VBA 3 06-25-2015 04:46 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:53 AM.


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