Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-23-2025, 03:39 AM
WJSwanepoel WJSwanepoel is offline VBA to turn a selected string into an equation Windows 10 VBA to turn a selected string into an equation Office 2021
Advanced Beginner
VBA to turn a selected string into an equation
 
Join Date: Dec 2019
Location: Krugersdorp, South Africa
Posts: 82
WJSwanepoel is on a distinguished road
Question VBA to turn a selected string into an equation

If I select a string such as
\(b = CA = \sqrt{(x_3 - x_1)^2 + (y_3 - y_1)^2}\)
I can turn it into a math equation by selecting Insert/Equation/Latex/convert/all professional
it then looks like attached image.



Can I do this by VBA, by selecting the text then executing the VBA?
Attached Images
File Type: jpg Equation.jpg (7.8 KB, 21 views)
Reply With Quote
  #2  
Old 01-23-2025, 01:39 PM
macropod's Avatar
macropod macropod is offline VBA to turn a selected string into an equation Windows 10 VBA to turn a selected string into an equation Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,381
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:
Code:
Sub ConvertEquation()
Application.ScreenUpdating = False
Dim Rng As Range, objEqn As OMath, Correction As OMathAutoCorrectEntry
Application.OMathAutoCorrect.UseOutsideOMath = True
Set Rng = Selection.Range: If Rng.End = Rng.Paragraphs.First.Range.End Then Rng.End = Rng.End - 1
For Each Correction In Application.OMathAutoCorrect.Entries
  If InStr(Rng.Text, Correction.Name) > 0 Then Rng.Text = Replace(Rng.Text, Correction.Name, Correction.Value)
Next
Rng.OMaths.Add(Rng).OMaths(1).BuildUp
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-23-2025, 10:27 PM
WJSwanepoel WJSwanepoel is offline VBA to turn a selected string into an equation Windows 10 VBA to turn a selected string into an equation Office 2021
Advanced Beginner
VBA to turn a selected string into an equation
 
Join Date: Dec 2019
Location: Krugersdorp, South Africa
Posts: 82
WJSwanepoel is on a distinguished road
Default It Works!

Thank you very much Macropod, it solves my problem.
Reply With Quote
Reply

Tags
math equation



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to turn a selected string into an equation Checking whether the selected lies with in an equation field Bikram Word VBA 4 03-19-2022 09:54 PM
VBA to turn a selected string into an equation Wildcard replace any string in context with a specified string wardw Word 7 05-07-2018 09:13 AM
VBA to turn a selected string into an equation How can I compare a string in a cell to another string? Amitti Word VBA 2 04-10-2017 07:35 PM
VBA to turn a selected string into an equation Way to search for a string in text file, pull out everything until another string? omahadivision Excel Programming 12 11-23-2013 12:10 PM
VBA to turn a selected string into an equation Why copying a paragraph to an equation ends without equation format??? Jamal NUMAN Word 2 04-24-2011 06:18 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:21 AM.


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