Sub Thongkeranh()Dim app As Excel.ApplicationOn Error Resume NextSet app = GetObject(, "Excel.Application")If Err <> 0 ThenErr.ClearSet app = CreateObject("excel.application")End If'Ket noi sang excelDim WBook As Workbook, WSheet As WorksheetSet WBook = app.Workbooks.AddSet WSheet = WBook.Worksheets(1)' Dat tieu de cho ranh: Range("A1").Value = "Lý trình b" & ChrW(7855) & "t " & ChrW(273) & ChrW(7847) & "u" Range("B1").Value = "Lý trình cu" & ChrW(7889) & "i" Range("C1").Value = "Chi" & ChrW(7873) & "u dài rãnh (m)" Range("D1").Value = "H" & ChrW(432) & ChrW(7899) & "ng rãnh" Range("E1").Value = ChrW(272) & ChrW(7897) & " d" & ChrW(7889) & "c rãnh"'''''''''''''''''''''''Dim diemcoso As VariantDim Goctoado As VariantDim Huongranh As StringDim lytrinh As DoubleDim lytrinh1 As DoubleDim batdau As VariantDim ketthuc As VariantGoctoado = ThisDrawing.Utility.GetPoint(, "Lua Chon Dau Km - Hay KM0+0.00: ")For i = 1 To 20On Error Resume Nextselect_sidetrack:' Vung Xanh nay de thong ke huong ranh ben (Khoa Vu87)'Huongranh : gia tri dien vao tieu de huong ranhHuongranh = ThisDrawing.Utility.GetString(fale, "lua chon huong ranh: ")''''bay loiIf Huongranh = "" Or Err <> 0 Then If MsgBox("ban chua lua chon huong ranh, chon yes de chon lai, no de thoat khoi chuong trinh", vbYesNo) = vbYes Then GoTo select_sidetrack Else Exit For End IfEnd If''''''''batdau : Diem bat dau lam ranh.batdau = ThisDrawing.Utility.GetPoint(, "lua chon diem bat dau ranh: ")lytrinh = Round(batdau(0) - Goctoado(0), 2)'ketthuc : Diem ket thuc lam ranh.ketthuc = ThisDrawing.Utility.GetPoint(, "lua chon diem ket thuc ranh: ")lytrinh1 = Round(ketthuc(0) - Goctoado(0), 2)Dim a As AcadObjectDim b As VariantThisDrawing.Utility.GetEntity a, diemcoso, "lua chon do doc ranh(%): "b = a.TextString'''''''''Cells(i + 1, 5).Value = bCells(i + 1, 4).Value = HuongranhCells(i + 1, 1).Value = lytrinh '-->Ly trinh dau.Cells(i + 1, 2).Value = lytrinh1 '-->Ly trinh cuoi.Cells(i + 1, 3).Value = Val(lytrinh1) - Val(lytrinh)Next iapp.Visible = TrueEnd Sub