> ## Documentation Index
> Fetch the complete documentation index at: https://support.taltech.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting past the 40 field limit in WinWedge

> How to use Excel VBA with WinWedge's DDE mode to collect device data records with more than 40 fields or longer than 255 bytes.

Excel's `DDERequest()` function has two limitations that affect WinWedge users working with complex devices:

1. `DDERequest()` always returns a Variant Array, not a string. String functions can't be applied directly to a Variant Array — you must first assign element 1 to a string variable.
2. `DDERequest()` can only return strings shorter than 255 bytes unless the data is tab-delimited. Longer strings are silently truncated.

## Workaround overview

Instead of relying on WinWedge's built-in field parsing, you let the data pass through as a few large chunks and parse it yourself in VBA. The approach:

1. Set the "End of Record Event" in WinWedge to "Carriage Return or CrLf Received"
2. Set the Record Structure to "Multiple Fixed Length Data Fields"
3. Define several 250-byte fields — enough to cover the largest possible record from your device (e.g., a 1125-byte record needs five 250-byte fields)
4. Set WinWedge to DDE Server mode
5. After the last defined field, enter `[RUN("NewGetSWData")]` as the "Field Postamble DDE Command"

Do not apply any filters to the defined fields.

This causes Excel to run the `NewGetSWData` subroutine after each complete data record is received.

## Excel VBA code

The subroutine below pulls all the chunks from WinWedge, reassembles them into a single string, parses the comma-delimited fields, and writes each field to a separate row in the spreadsheet.

```vb theme={null}
Sub NewGetSWData() ' this sub is run by the Wedge after each data record is received

Static R As Long, C As Long
' R & C point to the Row and Column where the data will go
If R = 0 Then R = 1: C = 1 ' make sure neither R or C is zero
Chan = DDEInitiate("WinWedge", "Com2")
' assume that there are 5 data fields defined - change to more or less if necessary
Field1 = Application.DDERequest(Chan, "Field(1)") ' get field 1
Field2 = Application.DDERequest(Chan, "Field(2)") ' get field 2
Field3 = Application.DDERequest(Chan, "Field(3)") ' get field 3
Field4 = Application.DDERequest(Chan, "Field(4)") ' get field 4
Field5 = Application.DDERequest(Chan, "Field(5)") ' get field 5
DDETerminate Chan ' kill the link
MyVar$ = Field1(1) & Field2(1) & Field3(1) & Field4(1) & Field5(1) & ","
' Convert each variant array to a string, concatenate them all together and
' add a final comma delimiter for the following parsing routine. The following
' code parses the string MyVar$ by searching for commas and placing each
' delimited field in a separate row
StartPos = 1 ' starting position in the string - start at 1st byte
While StartPos < Len(MyVar$) ' scan until we reach the end of the string
   DelimPos = InStr(StartPos, MyVar$, ",") ' find the next comma delimiter
   DataPoint$ = Mid$(MyVar$, StartPos, DelimPos - StartPos)
   ' pull out a data point between the starting position and the position of the delimiter
   StartPos = DelimPos + 1 ' update the starting position (skip over the delimiter)
   Sheets("Sheet1").Cells(R, C).Value = DataPoint$ ' save the current data point
   R = R + 1 ' point R to the next row down for the next data point
Wend ' go get the next point
R = 1 ' point R back to row 1
C = C + 1 ' increment C - move to the right one column for the next set of data

End Sub
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.