EDIdEv - Electronic Data Interchange Development

EDI Reader in MS Word

This is an example of a Visual Basic Script using the Framework EDI component in MS Word macro to translate and validate EDI files.

WordEdiTran.zip

How it Works
  • Open the WordEdiTran.doc document with MS Word
  • Run the ReadEdiFile macro by going to the menu and selecting Tools, Macro, then select the file from the list of Macros, and then click on Run.
  • Enter a SEF file when prompted.
  • Enter the EDI file you wish to read when prompted.

After the translation is complete, the data of the EDI file will be displayed along with its descriptions, making it easier to understand as shown below.

You can change the description of the segments and elements in the SEF file with our SEF Manager utility to make their descriptions more detailed and specific so that they can be better understood.  For example, an N1 segment's generic description of Name can be changed to Ship-To Name.

For more details about editing a SEF file with our SEF Manager, please visit Creating an Implementation Guideline

After the translation, any errors found in the EDI file will be reported at the end of the document.  The Segment Index is the segment count location where the particular error occurred.

The Visual Basic Script

The VB Script source code of the macro can be accessed by going to the menu and selecting Tools, Macro, then Visual Basic Editor.

            Sub ReadEDIfile()
            '
            ' ReadEDIfile Macro
            ' Macro created 5/3/2009 by edidev
            '
                Dim oEdiDoc As ediDocument
                Dim oSegment As ediDataSegment
                Dim oElement As ediDataElement
                Dim oElements As ediDataElements
                Dim oSubElement As ediDataElement
                Dim oWarnings As ediWarnings
                Dim oWarning As ediWarning
                Dim oSchemas As ediSchemas
    
                Dim sPath As String
                Dim i As Integer
                Dim ii As Integer
                Dim sSefFile As String
                Dim sEdifile As String
                Dim nErrCount As Integer
    
                Set oEdiDoc = New ediDocument
    
                Set oSchemas = oEdiDoc.GetSchemas
    
                'enable read of modified description in SEF file
                oSchemas.Option(OptSchemas_IncludeText) = 1
    
                oEdiDoc.CursorType = Cursor_ForwardOnly
    
                sPath = Application.ActiveDocument.Path & "\"
    
                'get and load SEF file
                sSefFile = InputBox("Enter SEF filename", "SEF File", "810_4010_modified.SEF")
                oEdiDoc.LoadSchema sPath & sSefFile, Schema_Standard_Exchange_Format
    
                'get and load EDI file
                sEdifile = InputBox("Enter EDI filename", "EDI File", "810.X12")
                oEdiDoc.LoadEdi sPath & sEdifile
    
                'traverse EDI file
                Set oSegment = oEdiDoc.FirstDataSegment
                Do While Not oSegment Is Nothing
    
                    Selection.Font.Bold = wdToggle
                    Selection.TypeText oSegment.ID & " - " & UCase(oSegment.Description) & vbCrLf
                    Selection.Font.Size = 8
                    Selection.TypeText oSegment.SegmentBuffer + vbCrLf
                    Selection.Font.Bold = wdToggle
                    Selection.Font.Reset
        
                    nElemCount = oSegment.Count
                    For i = 1 To nElemCount
            
                        Set oElement = oSegment.DataElement(i)
                        Set oElements = oElement.DataElements
                        nSubElemCount = oElements.Count
                        If nSubElemCount > 1 Then 'Composite Element
                            For ii = 1 To nSubElemCount
                                If Len(Trim(oSegment.DataElementValue(i, ii))) > 0 Then
                                    Set oSubElement = oElements.DataElement(ii)
                                    Selection.TypeText oSubElement.Description & ": "
                                    Selection.Font.Italic = wdToggle
                                    Selection.TypeText oSegment.DataElementValue(i, ii) & vbCrLf
                                    Selection.Font.Italic = wdToggle

                                End If
                            Next
                        Else    'Not a composite element
                            If Len(Trim(oSegment.DataElementValue(i))) > 0 Then
                                Selection.TypeText oElement.Description & ": "
                                Selection.Font.Italic = wdToggle
                                Selection.TypeText oSegment.DataElementValue(i) & vbCrLf
                                Selection.Font.Italic = wdToggle
                            End If
                        End If
                    Next
        
                    Selection.TypeText "" + vbCrLf
        
                    'get next segment
                    Set oSegment = oSegment.Next
        
                Loop
    
                Selection.TypeText "" & vbCrLf
                Selection.TypeText "" & vbCrLf
                Selection.TypeText "" & vbCrLf
                Selection.Font.Bold = wdToggle
                Selection.TypeText "Error messages" & vbCrLf
                Selection.Font.Bold = wdToggle
    
                'check for errors
                Set oWarnings = oEdiDoc.GetWarnings
                nErrCount = oWarnings.Count
                If nErrCount > 0 Then
                    For i = 1 To nErrCount
                        Set oWarning = oWarnings.Warning(i)
                        Selection.TypeText oWarning.Description & " "
                        Selection.Font.Bold = wdToggle
                        Selection.TypeText "Segment Index:" & oWarning.SegmentIndex & vbCrLf
                        Selection.Font.Bold = wdToggle
                        Selection.TypeText "" & vbCrLf
                    Next
                Else
                    Selection.TypeText "No errors found"
                End If
                Selection.Font.Reset

            End Sub
            

    Click here to download a trial version of the Framework EDI