STAAD.Pro Help

OS. Microsoft Word Macro Example

A Microsoft Office Word document is included which contains a partial report for analysis results which can be used as a basis for a customized report document.

The document file includes a macro named Pro which checks for the number of supported nodes as well as the number of load cases and load combinations and reports these back to the document. The document can then report support reactions for the selected node number and load case number.

  1. Open an input file within STAAD.Pro.
  2. Open the file C:\Users\Public\Public Documents\STAAD.Pro CONNECT Edition\Samples\OpenSTAAD\STAADandWord.doc.
    Note: Word will warn of macros present in the file. Simply click the Options… button in the Security Warning message area to open the Microsoft Office Security Options dialog, where you will select the Enable this Content option and click OK.
  3. Click the Update Nodes and Load Cases button. The Node Number and Load Case Number selectors update with the data from the selected file.
  4. Select the Node Number and Load Case Number numbers for which results will be retrieved.
  5. Click Get Results. The support reactions and units update in the table below.

Word Macro Code

To see what the OpenSTAAD macro is doing, use the developer tools to open the Visual Basic Editor.

GetSTAAD_Click

Option Explicit

Public objOpenSTAAD As Object
Public Fraction As Double
Public LC As Integer
Public bBadSTAADFile As Boolean



Private Sub GetSTAAD_Click()

'
' STAAD.Pro Macro
' Import STAAD.Pro Data Dynamically into an MS Word document
' using the OpenSTAAD Application object
 
    Dim stdFile As String
    Dim DOF As Integer
    Dim acell As Cell
  
  
     'Launch OpenSTAAD Object
    Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")
    
    'Load your STAAD file - make sure you have successfully run the file
    objOpenSTAAD.GetSTAADFile stdFile, "TRUE"
    STAADFileName.Text = "(None)"
    If stdFile = "" Then
        MsgBox "This macro can only be run with a valid STAAD file loaded.", vbOKOnly
        Set objOpenSTAAD = Nothing
        Exit Sub
    End If
  
    STAADFileName.Text = stdFile
    
    FillBoxesWithData stdFile

    DOF = 0
    For Each acell In ActiveDocument.Tables(2).Columns(2).Cells
        If (acell.RowIndex <> 1) Then
            acell.Range.Text = "0.0"
            DOF = DOF + 1
        End If
    Next acell



    Set objOpenSTAAD = Nothing
 
End Sub

GetResults1_Click

Private Sub GetResults1_Click()

    Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")

    Dim Reactions(6) As Double
    
    ' The Integer has been changed to a Long in 2004 to hold higher node numbers
    Dim Node As Long
    Dim LC As Long
    Dim DOF As Integer
    Dim acell As Cell
    
    If (bBadSTAADFile = True) Then
        MsgBox "Please provide a valid STAAD file, node number and load case number before clicking this button."
        Exit Sub
    End If

    Node = NodeNumber.Text
    LC = LCNumber.Text

    objOpenSTAAD.Output.GetSupportReactions Node, LC, Reactions

    DOF = 0
    For Each acell In ActiveDocument.Tables(2).Columns(2).Cells
        If (acell.RowIndex <> 1) Then
            acell.Range.Text = Reactions(DOF)
            DOF = DOF + 1
        End If
    Next acell


End Sub

Additional Subroutines

Private Function FillBoxesWithData(strSTAADFile As String)

    Dim varCounter1 As Integer
    Dim PrimaryLCs As Integer
    Dim LoadCombs As Integer
    Dim TotalLoads As Integer
    ' The Integer has been changed to a Long in 2004 to hold higher node numbers
    Dim SupportedNodesCount As Long
    ' The Integer has been changed to a Long in 2004 to hold higher node numbers
    Dim SupportedNodeNos() As Long


On Error GoTo ErrorHandler
'Set objOpenSTAAD = CreateObject("OpenSTAAD.Output.1")
    
    SupportedNodesCount = objOpenSTAAD.Support.GetSupportCount()
    ReDim SupportedNodeNos(SupportedNodesCount)
    
    Dim nReturn As Long
    
    nReturn = objOpenSTAAD.Support.GetSupportNodes(SupportedNodeNos)
    
    'Fill nodes list box
    NodeNumber.Clear
    For varCounter1 = 0 To SupportedNodesCount - 1
        NodeNumber.AddItem SupportedNodeNos(varCounter1)
    Next varCounter1
    
    NodeNumber.Text = SupportedNodeNos(0)
    
    'Fill load list box
    'Find out how many primary load cases and load combinations you have
    PrimaryLCs = objOpenSTAAD.Load.GetPrimaryLoadCaseCount()
    LoadCombs = objOpenSTAAD.Load.GetLoadCombinationCaseCount()
   
    TotalLoads = PrimaryLCs + LoadCombs
                
    LCNumber.Clear
    For varCounter1 = 1 To TotalLoads
         LCNumber.AddItem varCounter1
    Next
    LCNumber.Text = 1
    
    bBadSTAADFile = False

Exit Function

ErrorHandler:
    bBadSTAADFile = True
    MsgBox "STAAD File does not exist or proper analysis results cannot be found. Please check the STAAD file."

End Function

Private Sub NodeNumber_Change()

End Sub

Private Sub STAADFileName_Change()

End Sub

Private Sub UpdateSTDFile_Click()
 bBadSTAADFile = True
 FillBoxesWithData
End Sub