Use Excel vba to make equations in Word

leniusc

New Member
Joined
Jul 11, 2008
Messages
13
I have a spreadsheet (Excel 2007) that uses vba to create a Word 2007 document. Quite a few things flow from Excel to Word, including data and tables. Pushing info in that direction works fine.

However, I would like to insert equations into the Word document similar to Word's Equation Editor, but I can't seem to find a way to control Equation Editor through vba. I'm most in need of horizontal fractions. (Word 2007 calls these "professional.")

One solution would be if there was a way to control Equation Editor through vba. Does anyone know how?

Another solution might be to use LaTeX codes in Word. I've played around with it a little, but haven't found a way to, say, enter the code in a cell in Excel and have the equation show up in Word.

Another solution would be create equations in another way. I've read some about the EQ Field Code, but online documentation seems to be for Word 2003 rather than 2007, so I'm worried that this field code isn't supported anymore.

Anybody have advice about where to proceed?
Thanks,
Chris Lenius
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
In the absence of another reply .....

perhaps you could use pictures instead of actual data to copy into Word ?

eg. Copy/Paste or even Alt +Printscreen... Paste - and crop what you get down to size.
 
Upvote 0
Thanks for the image suggestion. I had already tried that using an online LaTeX editor to create images of the equations and insert those. However, the images were cumbersome to create, save, and then import, and worse yet they printed blurry for some reason.
I finally found a solution using the EQ field code.
In my Excel document, I'll have the user enter the fraction into a tag like <frac 1,2=""> for "one half". Then vba pastes this into Word and converts it into a field code.
For anyone interested, here is the main part of the vba code.
Thanks to anyone who thought about answering but couldn't figure it out.
-Chris
<code>
'make fraction codes into EQ fields
With wrdDoc.Content.Find 'Search for and count occurrences of <frac ___=""> tag.
Do While .Execute(FindText:="\<frac *\="">", MatchWildcards:=True, Forward:=True, Format:=True, _
MatchWholeWord:=True) = True
wNumFracs = wNumFracs + 1
Loop
End With
For i = 1 To wNumFracs
With wrdApp.Selection.Find 'find fractions
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute FindText:="\<frac *\="">"
End With
wFracName = Replace(Replace(wrdApp.Selection, "<frac ,="" ),="">", "") 'get numerator-comma-denominator
'Insert field code with fraction
wrdDoc.Fields.Add Range:=wrdApp.Selection.Range, _
Type:=wdFieldEmpty, _
Text:="EQ \f (" & wFracName & ")", _
PreserveFormatting:=False
Next i
</frac></frac></frac></frac></code></frac>
 
Upvote 0

Forum statistics

Threads
1,215,549
Messages
6,125,473
Members
449,233
Latest member
Deardevil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top