Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to import to UDT

Hi All!

I create UDT with name @MYUDT1 now I create button in UDT form (Open Form: Tool/User - Define Windows/ MYUDT1 ), When User Click it, will fill data into this UDT and data is get from Excel file. How to do it.?. Thanks

replied

hi,

Dim xlApp As Excel.Application

Dim xlSht As Excel.Worksheet

Dim xlRng As Excel.Range

Dim oMatrix As SAPbouiCOM.Matrix

Dim ExcelSheetName As String

oMatrix = oformBQ.Items.Item("5").Specific

xlApp = New Excel.Application

xlApp.DisplayAlerts = False

Try

xlApp.Workbooks.Open("Path of ExcelFile")

Catch ex As Exception

SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

Exit Function

End Try

For i = 1 To xlApp.Sheets.Count

If UCase(xlApp.Sheets.Item(i).Name) = UCase("Name of ExcelSheet") Then

xlSht = xlApp.Sheets(i)

If xlSht.UsedRange.Rows.Count > 0 Then

Continue = SBO_Application.MessageBox("Do you want to load Data From ImportBOQ.xls File", 1, "Yes", "No")

If Continue = 1 Then

For r = 1 To xlSht.UsedRange.Rows.Count

oformBQ.Freeze(True)

oMatrix.AddRow()

Try

oedit = oMatrix.Columns.Item(0).Cells.Item(r).Specific

oedit.Value = oMatrix.RowCount

xlRng = xlSht.Cells(r, 1)

oedit = oMatrix.Columns.Item("A1").Cells.Item(r).Specific

oedit.Value = xlRng.Value

xlRng = xlSht.Cells(r, 2)

oedit = oMatrix.Columns.Item("1").Cells.Item(r).Specific

oedit.Value = xlRng.Value

xlRng = xlSht.Cells(r, 3)

oedit = oMatrix.Columns.Item("2").Cells.Item(r).Specific

oedit.Value = xlRng.Value

Catch ex As Exception

SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

End Try

oMatrix.SelectRow(r, True, False)

oform.Update()

Next

SBO_Application.StatusBar.SetText("Data loaded successfully", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)

Exit Function

End If

Else

SBO_Application.StatusBar.SetText("No Data in Excel sheet " & RS.Fields.Item("PrjCode").Value, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

Exit Function

End If

End If

Next

regards,

varma

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question