I got the solution.........I write this in VBA
'open Excel
Dim oExcel As Excel.Application
Set oExcel = New Excel.Application
'Open the OLE excel file
Dim oWorkbook As Excel.Workbook
Set oWorkbook = oExcel.Workbooks.Open(ThisApplication.FileLocations.Workspace & "\" & "CONFIGURATION.xlsx")
'Get the sheet oMount
Dim oWorkSheet As WorkSheet
Set oWorkSheet = oWorkbook.Sheets.Item(i)
oExcel.Visible = False
For x = 2 To 19 Step 1
For y = 2 To 19 Step 1
If (oWorkSheet.Cells(x, 1) = BORE) And (oWorkSheet.Cells(y, 2) = MM) Then
If x = y Then
z = x
End If
End If
Next
Next
Select Case oMount
Case "MP5"
A = oWorkSheet.Cells(z, 4)
XO = oWorkSheet.Cells(z, 12)
SC = oWorkSheet.Cells(z, 16)
TotalL = A + XO + SC + UPSTROKE
D = oWorkSheet.Cells(z, 6)
TotalW = D
Case "MF3"
A = oWorkSheet.Cells(z, 4)
ZB = oWorkSheet.Cells(z, 12)
TotalL = A + ZB + UPSTROKE
UC = oWorkSheet.Cells(z, 16)
TotalW = UC
Case "MF4"
A = oWorkSheet.Cells(z, 4)
ZP = oWorkSheet.Cells(z, 12)
TotalL = A + ZP + UPSTROKE
UC = oWorkSheet.Cells(z, 16)
TotalW = UC
Case "MT4"
A = oWorkSheet.Cells(z, 5)
ZB = oWorkSheet.Cells(z, 13)
TotalL = A + ZB + UPSTROKE
TM = oWorkSheet.Cells(z, 20)
TL = oWorkSheet.Cells(z, 19)
TotalW = TM + TL * 2
Case "MS2"
A = oWorkSheet.Cells(z, 5)
ZJ = oWorkSheet.Cells(z, 13)
TotalL = A + ZJ + UPSTROKE
FW = oWorkSheet.Cells(z, 17)
TotalW = FW
End Select
oParams.Item("TotalL").Value = TotalL / 10
oParams.Item("TotalW").Value = TotalW / 10
MsgBox (TotalL)
MsgBox (TotalW)
oWorkbook.Close
oExcel.DisplayAlerts = False
oExcel.Quit
However, I got a small problems yesterday.
A window appears and say that my worksheet can be Read&Write now, and two button Read&Write button - Cancel button.
I think the end code needs some more lines.................
My brother wrote an ReleaseObject() code for me in VB.NET but I don't understand what it means. He said that it could release the memory, etc..........
Moreover, I can not translate it to VBA language.
Could the ReleaseObject() help in this situtation and for my problem?
releaseObject(oExcel)
releaseObject(oWorkbook)
releaseObject(oWorkSheet)
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
Could you tranfer it to VBA???
Many thanks in advance!