Post by mkolRalph;
Thank you for your quick response .What I am trying to to do is write some
math equations
say any equation...exmp ..equation$="y=a^bv*vcv*vdv2") (^=superscript ,,
v=subscript)
WordApp.Selection.TypeText Text:=pEqW(WordApp, "y=a^bv*vcv*vdv2")
Here is the function that does't work properly - including fonts, size-
Function pEqW(WordApp As Word.Application, ByVal equation As String)
' Dim rText As Range
Dim ch As String
Dim ixx As Long
'On Error GoTo pEqW_Error
WordApp.ActiveDocument.Select
With WordApp.Selection
.ClearFormatting
.Font.Name = "CourierNew"
.Font.Size = 10
.Font.Bold = False
For ixx = 1 To Len(equation)
ch = Mid$(equation, ixx, 1)
If ch = "^" Then
.Font.Size = 30
'.Font.Subscript = True
'.InsertBefore "^"
.Font.Superscript = True
.InsertAfter "^"
'.TypeText Text:=Mid$(equation, ixx + 1, 1)
ElseIf ch = "v" Then
.Font.Size = 30
'.Font.Superscript = True
.Font.Subscript = True
' '.MoveRight Unit:=wdCharacter, Count:=1
.InsertAfter "v"
ElseIf ch = " " Then
Else
'.TypeText Text:=ch
.Font.Size = 20
'.TypeText Text:=ch 'Mid$(equation, ixx, 1) '
'.Font.Subscript = False
'.Font.Superscript = False
.TypeText Text:=ch 'Mid$(equation, ixx, 1) '
.Font.Subscript = False
.Font.Superscript = False
End If
.Font.Subscript = False
.Font.Superscript = False
Next ixx
End With
WordApp.Selection.Font.Subscript = False
WordApp.Selection.Font.Superscript = False
WordApp.Selection.Font.Size = 8
WordApp.Selection.Font.Bold = False
'On Error GoTo 0
Exit Function
~~~~~~~~~~~~~~~~~~
Ralph,
Again Thanks,
M. Kol
Hopefully Mr. Shelton will be back with a response. He is one of the
Word gurus around here. (and I'm not set up to test your code atm)
But at first glance it appears you are not chewing on what you think
you are, or rather what you think you have 'selected' compared to what
Word thinks is currectly 'selected'.
Here is what I would try (it is essentially what I would do if I was
setup to test your code).
Open Word
Create a paragraph/panel or object where you want the result to
appear.
Create another dialog or paragraph/panel/object and enter the
characters as they would be delivered by VB in that panel.
Select the incoming text then create a keystroke macro to make the
format changes. That is likely going to take a while to get right.
Output the result to a separate buffer.
Then paste to where you want it.
(Most math/graphics translators do work with a separate buffer to
avoid confusing the intial selection with temp selections and final
results).
After that you can optimize it for your VB6 application.
If you intend to use a lot of math nomenclature/symbols etc. and you
aren't in the mood to become a Word Macro/Automation guru <g> there
are several 3rd party toys out there that will help. Some are limited
'free' tools, others are amazingly pricey.
MS Word comes with the Microsoft Equation Editor. I have no idea if it
can be automated or not, but might be worth looking into.
-ralph