Private Sub cmdTranslate_Click() Dim oEdiDoc As Fredi.ediDocument Dim oSchemas As Fredi.ediSchemas Dim oSegment As Fredi.ediDataSegment Dim mSefFile As String Dim mEdiFile As String Dim mRow, mCol As Integer Dim sPath As String Dim sEntity As String Dim sQlfr As String Dim sValue As String Dim sArea As String Dim sLoopSection As String Dim sSegmentID As String Cells(19, 5) = "Please wait gen..." sPath = Application.ActiveWorkbook.Path & "\" mSefFile = "834_X095.sef" mEdiFile = "834_x095.X12" Set oEdiDoc = New Fredi.ediDocument oEdiDoc.CursorType = Cursor_ForwardOnly Set oSchemas = oEdiDoc.GetSchemas oSchemas.EnableStandardReference = False 'Load SEF file oEdiDoc.LoadSchema sPath & mSefFile, 0 'Load EDI file oEdiDoc.LoadEdi sPath & mEdiFile 'Get first data segment Set oSegment = oEdiDoc.FirstDataSegment While Not oSegment Is Nothing 'A segment can be uniquely identified by checking its segment id, area and Loopsection sSegmentID = oSegment.ID sArea = oSegment.Area sLoopSection = oSegment.LoopSection If sArea = "0" Then If sSegmentID = "ISA" Then sValue = oSegment.DataElementValue(1) 'Authorization Information Qualifier sValue = oSegment.DataElementValue(2) 'Authorization Information sValue = oSegment.DataElementValue(3) 'Security Information Qualifier sValue = oSegment.DataElementValue(4) 'Security Information sValue = oSegment.DataElementValue(5) 'Interchange ID Qualifier sValue = oSegment.DataElementValue(6) 'Interchange Sender ID sValue = oSegment.DataElementValue(7) 'Interchange ID Qualifier sValue = oSegment.DataElementValue(8) 'Interchange Receiver ID sValue = oSegment.DataElementValue(9) 'Interchange Date sValue = oSegment.DataElementValue(10) 'Interchange Time sValue = oSegment.DataElementValue(11) 'Interchange Control Standards Identifier sValue = oSegment.DataElementValue(12) 'Interchange Control Version Number sValue = oSegment.DataElementValue(13) 'Interchange Control Number sValue = oSegment.DataElementValue(14) 'Acknowledgment Requested sValue = oSegment.DataElementValue(15) 'Usage Indicator sValue = oSegment.DataElementValue(16) 'Component Element Separator ElseIf sSegmentID = "GS" Then sValue = oSegment.DataElementValue(1) 'Functional Identifier Code sValue = oSegment.DataElementValue(2) 'Application Sender's Code sValue = oSegment.DataElementValue(3) 'Application Receiver's Code sValue = oSegment.DataElementValue(4) 'Date sValue = oSegment.DataElementValue(5) 'Time sValue = oSegment.DataElementValue(6) 'Group Control Number sValue = oSegment.DataElementValue(7) 'Responsible Agency Code sValue = oSegment.DataElementValue(8) 'Version / Release / Industry Identifier Code End If ElseIf sArea = "1" Then If sLoopSection = "" Then If sSegmentID = "ST" Then ' Transaction Set Header sValue = oSegment.DataElementValue(1) ' Transaction Set Identifier Code (143) sValue = oSegment.DataElementValue(2) ' Transaction Set Control Number (329) mRow = 1 ElseIf sSegmentID = "BGN" Then sValue = oSegment.DataElementValue(1) 'Transaction Set Purpose Code sValue = oSegment.DataElementValue(2) 'Reference Identification sValue = oSegment.DataElementValue(3) 'Date sValue = oSegment.DataElementValue(4) 'Time sValue = oSegment.DataElementValue(5) 'Time Code sValue = oSegment.DataElementValue(6) 'Reference Identification sValue = oSegment.DataElementValue(7) 'Transaction Type Code sValue = oSegment.DataElementValue(8) 'Action Code End If 'sSegmentID ElseIf sLoopSection = "N1" Then If sSegmentID = "N1" Then sEntity = oSegment.DataElementValue(1) If sEntity = "P5" Then 'Plan Sponsor Fed sValue = oSegment.DataElementValue(1) 'Entity Identifier Code sValue = oSegment.DataElementValue(2) 'Name sQlfr = oSegment.DataElementValue(3) 'Identification Code Qualifier If sQlfr = "FI" Then sValue = oSegment.DataElementValue(4) 'Identification Code End If ElseIf sEntity = "IN" Then 'Insurer Fed sValue = oSegment.DataElementValue(1) 'Entity Identifier Code sValue = oSegment.DataElementValue(2) 'Name sQlfr = oSegment.DataElementValue(3) 'Identification Code Qualifier If sQlfr = "FI" Then sValue = oSegment.DataElementValue(4) 'Identification Code End If End If End If 'sSegmentID End If 'sLoopSection ElseIf sArea = "2" Then If sLoopSection = "INS" Then If sSegmentID = "INS" Then mRow = mRow + 1 sValue = oSegment.DataElementValue(1) 'Yes/No Condition or Response Code sValue = oSegment.DataElementValue(2) 'Individual Relationship Code sValue = oSegment.DataElementValue(3) 'Maintenance Type Code sValue = oSegment.DataElementValue(4) 'Maintenance Reason Code sValue = oSegment.DataElementValue(5) 'Benefit Status Code sValue = oSegment.DataElementValue(6) 'Medicare Plan Code sValue = oSegment.DataElementValue(7) 'Consolidated Omnibus Budget Reconciliation Act (COBRA) Qualify sValue = oSegment.DataElementValue(8) 'Employment Status Code ElseIf sSegmentID = "REF" Then sQlfr = oSegment.DataElementValue(1) If sQlfr = "0F" Then 'Subscriber Cells(mRow, "L") = oSegment.DataElementValue(2) 'Reference Identification ElseIf sQlfr = "1L" Then 'Policy Cells(mRow, "M") = oSegment.DataElementValue(2) 'Reference Identification End If ElseIf sSegmentID = "DTP" Then sQlfr = oSegment.DataElementValue(1) 'Date/Time Qualifier If sQlfr = "356" Then 'Eligibilty Begin sValue = oSegment.DataElementValue(2) 'Date Time Period Format Qualifier Cells(mRow, "N") = oSegment.DataElementValue(3) 'Date Time Period End If End If ElseIf sLoopSection = "INS;NM1" Then If sSegmentID = "NM1" Then sEntity = oSegment.DataElementValue(1) 'Entity Identifier Code End If If sEntity = "IL" Then 'Insured or Subscriber If sSegmentID = "NM1" Then sValue = oSegment.DataElementValue(1) 'Entity Identifier Code sValue = oSegment.DataElementValue(2) 'Entity Type Qualifier Cells(mRow, "B") = oSegment.DataElementValue(3) 'Name Last or Organization Name Cells(mRow, "A") = oSegment.DataElementValue(4) 'Name First sValue = oSegment.DataElementValue(5) 'Name Middle sValue = oSegment.DataElementValue(6) 'Name Prefix sValue = oSegment.DataElementValue(7) 'Name Suffix sValue = oSegment.DataElementValue(8) 'Identification Code Qualifier Cells(mRow, "C") = oSegment.DataElementValue(9) 'Identification Code ElseIf sSegmentID = "PER" Then sValue = oSegment.DataElementValue(1) 'Contact Function Code sValue = oSegment.DataElementValue(2) 'Name sValue = oSegment.DataElementValue(3) 'Communication Number Qualifier Cells(mRow, "H") = oSegment.DataElementValue(4) 'Communication Number sValue = oSegment.DataElementValue(5) 'Communication Number Qualifier Cells(mRow, "I") = oSegment.DataElementValue(6) 'Communication Number ElseIf sSegmentID = "N3" Then Cells(mRow, "D") = oSegment.DataElementValue(1) 'Address Information ElseIf sSegmentID = "N4" Then Cells(mRow, "E") = oSegment.DataElementValue(1) 'City Name Cells(mRow, "F") = oSegment.DataElementValue(2) 'State or Province Code Cells(mRow, "G") = oSegment.DataElementValue(3) 'Postal Code ElseIf sSegmentID = "DMG" Then sValue = oSegment.DataElementValue(1) 'Date Time Period Format Qualifier Cells(mRow, "J") = oSegment.DataElementValue(2) 'Date Time Period Cells(mRow, "K") = oSegment.DataElementValue(3) 'Gender Code End If 'sSegmentID End If ElseIf sLoopSection = "INS;HD" Then If sSegmentID = "HD" Then sValue = oSegment.DataElementValue(1) 'Maintenance Type Code sValue = oSegment.DataElementValue(2) 'Maintenance Reason Code sEntity = oSegment.DataElementValue(3) 'Insurance Line Code ElseIf sSegmentID = "DTP" Then sValue = oSegment.DataElementValue(1) 'Date/Time Qualifier sValue = oSegment.DataElementValue(2) 'Date Time Period Format Qualifier If sEntity = "HLT" Then Cells(mRow, "P") = oSegment.DataElementValue(3) 'Date Time Period ElseIf sEntity = "DEN" Then Cells(mRow, "R") = oSegment.DataElementValue(3) 'Date Time Period ElseIf sEntity = "VIS" Then Cells(mRow, "T") = oSegment.DataElementValue(3) 'Date Time Period End If End If 'sSegmentID ElseIf sLoopSection = "INS;HD;COB" Then If sEntity = "HLT" Then If sSegmentID = "COB" Then sValue = oSegment.DataElementValue(1) ' Payer Responsibility Sequence Number Code (1138) sValue = oSegment.DataElementValue(2) ' Reference Identification (127) sValue = oSegment.DataElementValue(3) ' Coordination of Benefits Code (1143) ElseIf sSegmentID = "N1" Then sValue = oSegment.DataElementValue(1) ' Entity Identifier Code (98) sValue = oSegment.DataElementValue(2) ' Name (93) sValue = oSegment.DataElementValue(3) ' Identification Code Qualifier (66) sValue = oSegment.DataElementValue(4) ' Identification Code (67) sValue = oSegment.DataElementValue(5) ' Entity Relationship Code (706) sValue = oSegment.DataElementValue(6) ' Entity Identifier Code (98) End If End If End If 'sLoopSection ElseIf sArea = "3" Then End If 'sArea 'Get next data segment Set oSegment = oSegment.Next Wend Cells(19, 5) = "" MsgBox ("Done.") End Sub