Author Topic: A macro to insert Word 2010 new mathimatical equation into Visio 2010  (Read 14139 times)

0 Members and 1 Guest are viewing this topic.

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
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.

Code

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
« Last Edit: October 25, 2010, 11:58:33 PM by JuneTheSecond »
Best Regards,

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

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: A macro to insert Word 2010 new mathimatical equation into Visio 2010
« Reply #1 on: October 27, 2010, 07:47:03 AM »
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.

Code
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

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: A macro to insert Word 2010 new mathimatical equation into Visio 2010
« Reply #2 on: October 27, 2010, 07:49:15 AM »
Here is the Visio drawing.
Best Regards,

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

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: A macro to insert Word 2010 new mathimatical equation into Visio 2010
« Reply #3 on: October 28, 2010, 06:08:53 AM »
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

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: A macro to insert Word 2010 new mathimatical equation into Visio 2010
« Reply #4 on: October 28, 2010, 06:10:14 AM »
And more example.
Best Regards,

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

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: A macro to insert Word 2010 new mathimatical equation into Visio 2010
« Reply #5 on: October 28, 2010, 06:13:25 AM »
And
Best Regards,

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

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: A macro to insert Word 2010 new mathimatical equation into Visio 2010
« Reply #6 on: October 29, 2010, 03:05:35 AM »
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.
« Last Edit: October 29, 2010, 03:10:14 AM by JuneTheSecond »
Best Regards,

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