A macro to insert Word 2010 new mathimatical equation into Visio 2010

Started by JuneTheSecond, October 26, 2010, 04:48:21 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JuneTheSecond

This macro inserts Word OMath equation e^iwt on Visio 2010 page.
Please, enjoy.

Visio 2010 and Word 2010 must be installed.
And  you need to add reference to Word 14.0 object library.



Sub InsertOmath()
   Dim shp As Visio.Shape
   Dim wrdMath As Word.OMath
   Dim wrdObj As Word.Document
   Dim wrdRange As Word.Range
   Dim wrdSelection As Word.Selection
   Dim widthShp As Double
   
   On Error GoTo ERRHND
   
   Set shp = Application.ActiveWindow.Page.InsertObject("Word.Document", visInsertAsEmbed)
   Set wrdObj = shp.Object
   Set wrdRange = wrdObj.Range
   
   Set wrdSelection = wrdObj.Application.Selection
   Set wrdRange = wrdSelection.Range
   wrdRange.OMaths.Add Range:=wrdRange
   Selection.OMaths.Add Range:=Selection.Range
   wrdSelection.TypeText Text:="e^(-i"
   wrdSelection.InsertSymbol 969, , True, 0
'    CharacterNumber:=969, Unicode:=True, Bias:=0
   wrdSelection.TypeText Text:="t)"
   wrdSelection.OMaths.BuildUp
   wrdSelection.EscapeKey
   
   shp.Cells("Width").Formula = "3 mm"
   
   Exit Sub
   
ERRHND:
   If Err.Number = 462 Then
       Debug.Print "462 Error Resumed"
       Resume Next
   Else
       Debug.Print Err.Number, Err.Description
   End If
   
End Sub
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

Modified macro that convert text type formula into mathematical equation.
Input is the text in each rectangle on the left.
Your Visio needs to display unicode characters.


Sub InsertOmath()
    Dim shp As Visio.Shape
    Dim input_text As String
    Dim wrdMath As Word.OMath
    Dim wrdObj As Word.Document
    Dim wrdRange As Word.Range
    Dim wrdSelection As Word.Selection
   
    On Error GoTo ERRHND
       
    input_text = ActiveWindow.Selection(1).Text
    Set shp = Application.ActiveWindow.Page.InsertObject("Word.Document", visInsertAsEmbed)
    shp.Cells("Width").Formula = "3 mm"

    Set wrdObj = shp.Object
   
   
    Set wrdRange = wrdObj.Range
   
    Set wrdSelection = wrdObj.Application.Selection
    Set wrdRange = wrdSelection.Range
    wrdRange.OMaths.Add Range:=wrdRange
    Selection.OMaths.Add Range:=Selection.Range
   
    wrdSelection.TypeText Text:=input_text
    wrdSelection.OMaths.BuildUp
   
    wrdSelection.WholeStory

'    wrdObj.ApplyQuickStyleSet2 ("ストロー") ' may be "Straw" in English.
    wrdObj.ApplyQuickStyleSet2 ("シンプル") 'may be "Simple" in English.
'    wrdSelection.Style = wrdObj.Styles("表題") ' may be "Tytle" in English.
    wrdSelection.Style = wrdObj.Styles("標準") ' may be "Standard" in English
'    wrdSelection.Font.ColorIndex = wdBrightGreen
    wrdSelection.Font.ColorIndex = wdBlack
    wrdSelection.Font.Size = 20
   
    wrdSelection.EscapeKey
   
    Exit Sub
   
ERRHND:
    If Err.Number = 462 Then
        Debug.Print "462 Error Resumed"
        Resume Next
    Else
        Debug.Print Err.Number, Err.Description
    End If
   
End Sub
Best Regards,

Junichi Yoda
http://june.minibird.jp/


JuneTheSecond

Mathematical equation can be converted into Visio shape.
And can be filled with color or with fill pattern.
1. Convert text in the shape into Word 2010 Equation, with style "Straw".
2. Convert the equation into Visio shape, fill color or fill pattern.
Best Regards,

Junichi Yoda
http://june.minibird.jp/



JuneTheSecond

This is a macro that makes directly Visio shape of equation from the text type equation on the input shape.
Select type of the Visio shape from "Type" in the shape data.
1. "Embeded" makes equation on embeded Word 2010 object.
2. "Group" makes equation in Visio group shape.
3. "Union" makes equation on sigle shape.
Best Regards,

Junichi Yoda
http://june.minibird.jp/