Revit VSTA – reading values from excel

here is how you access EXCEL from REVIT VSTA and get values (i.e. coordinates of points of whatever you need it) from an excel sheet.

you’ll have to play with the cell numbers in the code because they are specific for my spreadsheet but you get the point!

Enjoy!

 

 ’open Excel and get geometry
        Dim my_excel As Microsoft.Office.Interop.Excel.Application
        my_excel = CType(GetObject(, “Excel.Application”), Application)
        Dim my_sheet As New Microsoft.Office.Interop.Excel.Worksheet
        my_sheet = my_excel.ActiveWorkbook.ActiveSheet
        my_sheet.Activate()
        Dim i As Integer
        Dim j As Integer
        For i = 2 To 4
            j = i + 1
            ‘********** POINT FROM EXCEL ***********
            Dim my_x As Double
            Dim my_y As Double
            Dim my_z As Double
            Dim rangerX As Microsoft.Office.Interop.Excel.Range = Nothing
            Try
                rangerX = my_sheet.Cells(i, 2)
                my_x = rangerX.Value2.ToString
            Catch ex As Exception
            End Try
            Dim rangerY As Microsoft.Office.Interop.Excel.Range = Nothing
            Try
                rangerY = my_sheet.Cells(i, 3)
                my_y = rangerY.Value2.ToString
            Catch ex As Exception
            End Try
            Dim rangerZ As Microsoft.Office.Interop.Excel.Range = Nothing
            Try
                rangerZ = my_sheet.Cells(i, 4)
                my_z = rangerZ.Value2.ToString
            Catch ex As Exception
            End Try

Leave a Reply