Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

How to get strings from equation through VBA code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert L - 13 Dec 2004 15:13 GMT
Hi All,

I'd like to know if it is possible to get strings from equation that is
embedded in Word document using VBA code (Word 2000). I tried to record
macro, but it did not. Also I did not find any help on this. Does anyone
know it is possible at all and if so, how?

Thank you very much in advance.
Regards,
Robert
Word Heretic - 13 Dec 2004 23:03 GMT
G'day "Robert L" <address923@hotmail.com>,

Alt+F9 to reveal field codes.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice

Robert L reckoned:

>Hi All,
>
[quoted text clipped - 6 lines]
>Regards,
>Robert
macropod - 14 Dec 2004 01:42 GMT
hi Robert,

Try the following, which I picked up somewhere:

Sub FieldCodeToString()
   Dim Fieldstring As String, NewString As String, CurrChar As String
   Dim CurrSetting As Boolean, fcDisplay As Object
   Dim MyData As DataObject, X As Integer
   NewString = ""
   Set fcDisplay = ActiveWindow.View
   Application.ScreenUpdating = False
   CurrSetting = fcDisplay.ShowFieldCodes
   If CurrSetting <> True Then fcDisplay.ShowFieldCodes = True
   Fieldstring = Selection.Text
   For X = 1 To Len(Fieldstring)
       CurrChar = Mid(Fieldstring, X, 1)
       Select Case CurrChar
           Case Chr(19)
               CurrChar = "{"
           Case Chr(21)
               CurrChar = "}"
           Case Else
       End Select
       NewString = NewString + CurrChar
   Next X
   Set MyData = New DataObject
   MyData.SetText NewString
   MyData.PutInClipboard
   fcDisplay.ShowFieldCodes = CurrSetting
End Sub

Select the field then run the code. The code puts the field's coding into
the clipboard, from where you can paste it into whatever application you
want.

Cheers
PS: You'll need to include a vba reference to the Microsoft Forms 2.0 (or
later) object library.

> Hi All,
>
[quoted text clipped - 6 lines]
> Regards,
> Robert
Jay Freedman - 14 Dec 2004 04:34 GMT
>hi Robert,
>
>Try the following, which I picked up somewhere:
>
>Sub FieldCodeToString()

All that is fine if Robert's "equation" is an EQ field (although even
then the field code doesn't look much like the printed equation). If
it's an Equation Editor object, all he'll get from the macro is the
string "EMBED Equation 3".

AFAIK, there's no way to extract the text of the equation from an
Equation Editor object. Maybe Bob Mathews of Design Science will drop
in to let us know whether MathType has an interface to VBA that can do
it.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org
Robert L - 14 Dec 2004 07:36 GMT
Hi,

thank you all three for your replies. But unfortunatelly the macropod's code
returns only "EMBED Equation 3", just like Jay supposed :) So it seems there
is no way for me to make my macro do this. It's a pity because the macro
extracts texts from pictures fine, but because of this, part of the job will
have to be done manually :(

Anyway, I thank you all three for your replies very much (and macropod for
the code. I will use it in some other macros:).
Best regards,
Robert
macropod - 14 Dec 2004 08:21 GMT
Hi Robert,

For future reference, a possible workaround is to insert your equations as
EQ fields, instead of via the Equation Editor. You can get much the same
result, in terms of appearance but, instead of a bitmap, you get a real
text-based field that will sit in-line with other text by default. EQ fields
will adopt whatever style/formatting you apply to the rest of the paragraph
(unless you add a Charformat switch). Plus, you can edit them!

Cheers

> Hi,
>
[quoted text clipped - 8 lines]
> Best regards,
> Robert
Robert L - 14 Dec 2004 09:31 GMT
Hi macropod,

Unfortunately, the Word documents that I run my macro on are created by
people in another company. So I cannot influence this. But the equations
appear in the docs rarely, so it should not be a big problem to retype texts
from equation(s) to another document manually.

Thank you very much once more.
Regards,
Robert

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.