The following article shows an easy way to create STAAD files directly from Excel worksheets.
So, at first,
Create a worksheet that has the same format as the STAAD input file for your structure. This totally depends upon your structure or analysis requirement. All the lines should be as text in the same column.
For example, I am sharing a screenshot of the excel worksheet which was made exactly in the input format matching my Structural and analysis requirements. The advantage of using excel is that the input for the structure can be changed rapidly and thus a large number of files having same structure type but different dimensions can be created.
Make sure it is in exact same format as of a STAAD input file.
then,
Use the code given below to create an Excel Macro in VBA. What this code does is create the STAAD file in the same directory as of the Excel file and opens it in the background. In further stages, we will try to develop Macros in such a way that the whole analysis part could be completed and results could be imported to excel workbook directly.
To run the code,
Option Explicit
Declare PtrSafe Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Function OpenAnyFile(FileToOpen As String)
Call ShellExecute(0, "Open", FileToOpen & vbNullString, _
vbNullString, vbNullString, 1)
End Function
Function RemovePunctuation(r As String) As String
With CreateObject("vbscript.regexp")
.Pattern = "[^*/.()-=+[]<>A-Z0-9 ]" 'Given are the various symbols that the function will keep in the STAAD file
.IgnoreCase = True
.Global = True
RemovePunctuation = .Replace(r, "")
End With
End Function
Sub STAADCreator()
Dim stdFile As Object
Dim ws As Worksheet
Dim cll As Range
Dim fpath As String
Dim LastRow As Long
Set ws = Worksheets("STAAD_InputFile_Main") 'Your worksheet name or activeworksheet property can be used
fpath = Application.ActiveWorkbook.Path
If Right(fpath, 1) <> "\" Then fpath = fpath & "\"
LastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row 'Here all the input is as text in column A
With CreateObject("Scripting.FileSystemObject")
Set stdFile = .CreateTextFile(fpath & "STAAD_Main.std", True) 'Your STAAD File name
End With
For Each cll In ws.Range("A1:A" & LastRow)
stdFile.WriteLine (RemovePunctuation(cll.Value))
Next cll
stdFile.Close
Call OpenAnyFile(ThisWorkbook.Path & "\STAAD_Main.std") 'Command to open your STAAD file
End Sub
Add a button in the worksheet itself so as to execute the code. Buttons can be added through Developer tab in Excel.
This will create and open your STAAD file right after you run the code.
So, at first,
Create a worksheet that has the same format as the STAAD input file for your structure. This totally depends upon your structure or analysis requirement. All the lines should be as text in the same column.
For example, I am sharing a screenshot of the excel worksheet which was made exactly in the input format matching my Structural and analysis requirements. The advantage of using excel is that the input for the structure can be changed rapidly and thus a large number of files having same structure type but different dimensions can be created.
Make sure it is in exact same format as of a STAAD input file.
then,
Use the code given below to create an Excel Macro in VBA. What this code does is create the STAAD file in the same directory as of the Excel file and opens it in the background. In further stages, we will try to develop Macros in such a way that the whole analysis part could be completed and results could be imported to excel workbook directly.
To run the code,
- Open Microsoft Excel and Press alt+F11 to open Macros editor.
- Paste the following code in a new module with suitable changes as per your requirements.
Option Explicit
Declare PtrSafe Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Function OpenAnyFile(FileToOpen As String)
Call ShellExecute(0, "Open", FileToOpen & vbNullString, _
vbNullString, vbNullString, 1)
End Function
Function RemovePunctuation(r As String) As String
With CreateObject("vbscript.regexp")
.Pattern = "[^*/.()-=+[]<>A-Z0-9 ]" 'Given are the various symbols that the function will keep in the STAAD file
.IgnoreCase = True
.Global = True
RemovePunctuation = .Replace(r, "")
End With
End Function
Sub STAADCreator()
Dim stdFile As Object
Dim ws As Worksheet
Dim cll As Range
Dim fpath As String
Dim LastRow As Long
Set ws = Worksheets("STAAD_InputFile_Main") 'Your worksheet name or activeworksheet property can be used
fpath = Application.ActiveWorkbook.Path
If Right(fpath, 1) <> "\" Then fpath = fpath & "\"
LastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row 'Here all the input is as text in column A
With CreateObject("Scripting.FileSystemObject")
Set stdFile = .CreateTextFile(fpath & "STAAD_Main.std", True) 'Your STAAD File name
End With
For Each cll In ws.Range("A1:A" & LastRow)
stdFile.WriteLine (RemovePunctuation(cll.Value))
Next cll
stdFile.Close
Call OpenAnyFile(ThisWorkbook.Path & "\STAAD_Main.std") 'Command to open your STAAD file
End Sub
Add a button in the worksheet itself so as to execute the code. Buttons can be added through Developer tab in Excel.
This will create and open your STAAD file right after you run the code.
Very Helpful.. the code works perfectly
ReplyDeleteWORKS FINE,
ReplyDeleteCan we create a folder first "STD" in same location first then before open staad file we first move them to folder.
not working
ReplyDelete