Import ANSYS MAPDL Plots into PowerPoint

Inserting multiple pictures from ANSYS hardcopy outputs into Microsoft PowerPoint presentations is something we do often. PADT has developed a PowerPoint Visual Basic macro to speed this process up significantly. You can run the macro by opening the macro menu (Alt-F8) in PowerPoint, and then running the "insert" macro. The following information should be entered into the dialog boxes, when prompted:

  1. Full path of the pictures to be imported
  2. Source file name (ANSYS increments filenames for pictures using sourcefilenamexxx)
  3. Types of files to import (e.g., jpg, png, tif, etc.)
  4. Starting slide position in the PowerPoint document (normally 1)
  5. Number of pictures to import

Cut and paste the macro source code listed below into your own presentation. Once PowerPoint is launched, run macro "insert4".

Import ANSYS Output into PowerPoint

Inserting multiple pictures from ANSYS hardcopy outputs into Microsoft PowerPoint presentations is something we do often. PADT has developed a PowerPoint Visual Basic macro to speed this process up significantly. You can run the macro by opening the macro menu (Alt-F8) in PowerPoint, and then running the “insert” macro.

The following information should be entered into the dialog boxes, when prompted:

  1. Full path of the pictures to be imported
  2. Source file name (ANSYS increments filenames for pictures using sourcefilenamexxx)
  3. Types of files to import (e.g., jpg, png, tif, etc.)
  4. Starting slide position in the PowerPoint document (normally 1)
  5. Number of pictures to import

You can download a sample PowerPoint file, which includes the macro, by clicking the link below. Or you can cut and paste the macro source code listed below into your own presentation. Once PowerPoint is launched, run macro “insert4”.

Macro Source Code

Sub insert()
' Macro recorded by Alex Grishin
' Modified by Joe Woodward
Dim iStartLoc As Integer
Dim sStartLoc As String
Dim iNumSlide As Integer
Dim sNumSlide As String
Dim iTest As Integer
Dim sPath As String
Dim sSFile As String
Dim sFPath As String
sPath = InputBox(Prompt:="Input directory path of file", Default:="./")
' sPath = "D:\alex\Mta\new_geo\softmount\delay"
sSFile = InputBox(Prompt:="Input source file name")
' sSFile = "delsoft"
sTAG = InputBox(Prompt:="Input file type tag. (Ex. tif,jpg,gif)", Default:="tif")
sStartLoc = InputBox(Prompt:="Input Starting Slide Location")
iStartLoc = Val(sStartLoc)
' iStartLoc = 9
sNumSlide = InputBox(Prompt:="Input Number of Slides to Read In")
iNumSlide = Val(sNumSlide)
' iNumSlide = 31
For I = 1 To iNumSlide
  If I <= 10 Then _
  sFPath = sPath + "\" + sSFile + sNTStr(0) + sNTStr(0) + sNTStr(I - 1) + "." + sTAG
  If I > 10 Then _
    sFPath = sPath + "\" + sSFile + sNTStr(0) + sNTStr(I - 1) + "." + sTAG
  ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add( _
    Index:=iStartLoc + I - 1, Layout:=ppLayoutBlank).SlideIndex
  ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:=sFPath, _
    LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=4, _
    Top:=0, Width:=713, Height:=540).Select
  With ActiveWindow.Selection.ShapeRange
    .Height = 413.88
    .Width = 546.25
    .Left = 77.62
    .Top = 49.62
  End With
Next I
End Sub

Function sNTStr(Num As Integer) As String
Dim iOnes As Integer
Dim iTens As Integer
Dim iHunds As Integer
Dim iThous As Integer
iOnes = Num
iTens = Int(Num / 10)
iHunds = Int(Num / 100)
iThous = Int(Num / 1000)
If Num < 10 Then sNTStr = Chr(iOnes + 48)
If Num > 9 And Num < 100 Then
  iOnes = Num - iTens * 10
  sNTStr = Chr(iTens + 48) + Chr(iOnes + 48)
End If
If Num > 99 And Num < 1000 Then
  iTens = Int((Num - iHunds * 100) / 10)
  iOnes = Num - iHunds * 100 - iTens * 10
  sNTStr = Chr(iHunds + 48) + Chr(iTens + 48) + Chr(iOnes + 48)
End If
If Num > 999 And Num < 10000 Then
  iHunds = Int((Num - iThous * 1000) / 100)
  iTens = Int((Num - iThous * 1000 - iHunds * 100) / 10)
  iOnes = Num - iThous * 1000 - iHunds * 100 - iTens * 10
  sNTStr = Chr(iThous + 48) + Chr(iHunds + 48) + Chr(iTens + 48) + Chr(iOnes + 48)
End If
End Function

 

Back to Top