Import Fixed-Width LS-DYNA Data into Excel with VBA
Question details
Import fixed-width LS-DYNA keyword data into a spreadsheet using VBA without relying on spaces between values.

- Product
- Microsoft Excel VBA and LS-DYNA keyword files
- Device & OS
- not provided
- Scenario
- A user needs to read LS-DYNA records whose field boundaries are defined by character positions.
- Observed behavior
- Adjacent values may have no separating spaces, so a delimiter-based import cannot reliably identify the fields.
Check the LS-DYNA documentation or file specification for the field positions and widths of each record type you need to import. Open the file in a text editor to identify keyword lines, comments, and the data records that follow them.
Extract fixed-width fields with Excel VBA
Use VBA to read each line and extract fields by character position rather than by spaces or other delimiters.
The sample below extracts two 10-character fields as a starting point only; these widths are not a universal LS-DYNA layout. Replace them with the documented positions and widths for your file, and add logic to handle each keyword and record type.
The macro imports every line, including keywords and comments, so you can inspect the results before adding record-specific rules.
In desktop Excel, open the workbook, press Alt+F11, and select Insert > Module in the VBA editor.
Paste this sample into the module: Sub ImportFixedWidth() Dim filePath As Variant, fileNum As Integer Dim lineText As String, rowNum As Long Dim ws As Worksheet filePath = Application.GetOpenFilename("All files (*.*),*.*", , "Select LS-DYNA file") If filePath = False Then Exit Sub Set ws = ThisWorkbook.Worksheets.Add ws.Range("A:C").NumberFormat = "@" ws.Range("A1").Value = "Original line" ws.Range("B1").Value = "Field 1" ws.Range("C1").Value = "Field 2" rowNum = 2 fileNum = FreeFile Open CStr(filePath) For Input As #fileNum Do While Not EOF(fileNum) Line Input #fileNum, lineText ws.Cells(rowNum, 1).Value = lineText ws.Cells(rowNum, 2).Value = Mid$(lineText, 1, 10) ws.Cells(rowNum, 3).Value = Mid$(lineText, 11, 10) rowNum = rowNum + 1 Loop Close #fileNum End Sub
In the module, change each Mid$ start position and width to match the relevant LS-DYNA record specification. Add conditions that identify keyword and comment lines and select the appropriate layout for each data record.
In Excel, open Developer > Macros, select ImportFixedWidth, and click Run. Choose the keyword file, then compare the new worksheet's original lines and extracted fields with the documented layouts.
Use File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm) if you want to keep the VBA code in the workbook.

Review Imported LS-DYNA Data in WPS Spreadsheets
WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface and compatibility with Excel formats, making it easy to move imported data between applications. It does not fix the Excel VBA import or guarantee that an Excel macro will run unchanged.

Frequently Asked Questions
Why can't I split the LS-DYNA file on spaces?
Fixed-width fields are defined by character positions, and adjacent values may have no space between them. Use Mid$(lineText, startPosition, fieldWidth) with the documented layout instead.
How do I know which field widths to use?
Check the LS-DYNA specification for each keyword and record type in your file. The two 10-character fields in the sample are illustrative and must be replaced with the applicable positions and widths.
How can I preserve leading zeros in imported fields?
Format the destination cells as text before writing values. The sample sets columns A through C to text with NumberFormat = "@" and writes the extracted strings without converting them to numbers.
Can the same VBA layout be used for every line?
Not necessarily. Keyword lines, comments, and different data record types can have different structures. Add VBA conditions to identify them and apply the appropriate field layout.




