Sub Get_Job_Info()
On Error GoTo ErrorHandler
Call LogStatus.LogProgress("Getting Job Info")
' Get the application object
Dim objOpenSTAAD As Object
Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")
If objOpenSTAAD Is Nothing Then
MsgBox "STAAD.Pro is not running or OpenSTAAD is unavailable.", vbCritical
Exit Sub
End If
' Create or clear the "JobInfo" sheet
Dim ws As Worksheet
On Error Resume Next
Set ws = Worksheets("JobInfo")
On Error GoTo 0
If ws Is Nothing Then
Set ws = Worksheets.Add(After:=ActiveSheet)
ws.Name = "JobInfo"
Else
' Clear all contents
ws.Cells.Clear
' Reset outline levels
ws.Outline.ShowLevels RowLevels:=1, ColumnLevels:=1
End If
' Get Job Info
Dim jobName As String, jobClient As String, enggName As String, eDate As String
Dim jobNumber As String, revision As String, part As String, reference As String
Dim checkerName As String, chDate As String, approverName As String, aDate As
String
Dim comments As String, statusDescription As String
objOpenSTAAD.GetFullJobInfo jobName, jobClient, enggName, eDate, jobNumber,
revision, part, reference, checkerName, chDate, approverName, aDate, comments
' Get Base Unit Info
Dim BaseUnitNo As Long
BaseUnitNo = objOpenSTAAD.GetBaseUnit()
'Retrieve the entire path
Dim fileName As String
Dim bFullPath As Boolean
bFullPath = True
objOpenSTAAD.GetSTAADFile fileName, bFullPath
' Get Analysis Info
Dim NoOfWarnings As Long, NoOfErrors As Long
Dim CPUTime As Double, AnalysisStatus As Long
AnalysisStatus = objOpenSTAAD.GetAnalysisStatus(fileName, NoOfWarnings,
NoOfErrors, CPUTime)
' Prepare log data
Dim logData(1 To 20, 1 To 2) As Variant
logData(1, 1) = "Job Name": logData(1, 2) = jobName
logData(2, 1) = "Client": logData(2, 2) = jobClient
logData(3, 1) = "Engineer": logData(3, 2) = enggName
logData(4, 1) = "Engineer Date": logData(4, 2) = eDate
logData(5, 1) = "Job Number": logData(5, 2) = jobNumber
logData(6, 1) = "Revision": logData(6, 2) = revision
logData(7, 1) = "Part": logData(7, 2) = part
logData(8, 1) = "Reference": logData(8, 2) = reference
logData(9, 1) = "Checker": logData(9, 2) = checkerName
logData(10, 1) = "Checker Date": logData(10, 2) = chDate
logData(11, 1) = "Approver": logData(11, 2) = approverName
logData(12, 1) = "Approval Date": logData(12, 2) = aDate
logData(13, 1) = "Comments": logData(13, 2) = comments
logData(14, 1) = "Base Unit No": logData(14, 2) = BaseUnitNo
logData(15, 1) = "AnalysisStatus": logData(15, 2) = AnalysisStatus
logData(16, 1) = "Status Description": logData(16, 2) = statusDescription
logData(17, 1) = "Warnings": logData(17, 2) = NoOfWarnings
logData(18, 1) = "Errors": logData(18, 2) = NoOfErrors
logData(19, 1) = "CPU Time (s)": logData(19, 2) = Round(CPUTime, 2)
logData(20, 1) = "Retrieved On": logData(20, 2) = Format(Now, "yyyy-mm-dd
hh:nn:ss")
' Write headers and results
ws.Range("A1:B1").Value = Array("Parameter", "Value")
ws.Range("A2:B21").Value = logData
ws.Columns("A:B").AutoFit
ws.Range("A1:B1").Font.Bold = True
' Apply XLOOKUP for Base Unit Description
Dim formulaRange As Range
Set formulaRange = ws.Range("C15")
formulaRange.FormulaR1C1 = "=XLOOKUP(RC[-
1],'STAAD_SECTION_TYPE_TABLE'!R17C10:R18C10,'STAAD_SECTION_TYPE_TABLE'!R17
C11:R18C11,""NA"",0)"
' Apply XLOOKUP for Status Description
Dim formulaRange1 As Range
Set formulaRange1 = ws.Range("B17")
formulaRange1.FormulaR1C1 = "=XLOOKUP(R[-
1]C,'STAAD_SECTION_TYPE_TABLE'!R21C10:R28C10,'STAAD_SECTION_TYPE_TABLE'!R2
1C11:R28C11,""NA"",0)"
'Get file path
ws.Range("D2").Value = "File Path"
ws.Range("E2").Value = fileName
'Input unit of force and Length of the currently open .STD file.
Dim ForceUnit As String
Dim LengthUnit As String
objOpenSTAAD.GetInputUnitForForce ForceUnit
objOpenSTAAD.GetInputUnitForLength LengthUnit
ws.Range("D3").Value = "Force Unit"
ws.Range("E3").Value = ForceUnit
ws.Range("D4").Value = "Length Unit"
ws.Range("E4").Value = LengthUnit
'Autofit columns
ws.Columns("A:E").AutoFit
Call LogStatus.LogProgress("Job information retrieved and logged successfully.")
Application.StatusBar = False
Exit Sub
ErrorHandler:
MsgBox "An error occurred: " & Err.Description, vbCritical
Application.StatusBar = False
End Sub