VB.NET EXCEL LAST COLUMN, VB 엑셀 마지막 컬럼 구하기

2016. 9. 9. 11:15IT/MS-SQL

반응형

 

        Dim xls As New Excel.Application
        Dim xWorkbook As Excel.Workbook
        Dim xWorksheet As Excel.Worksheet
        Dim xRange As Excel.Range
        Dim xlotno As String
        Dim lColumn As Long = 0

        xWorkbook = xls.Workbooks.Open("E:\1234512345.xls") 'File Location
        xWorksheet = xWorkbook.Sheets(1)

        With xWorksheet
            If xls.WorksheetFunction.CountA(.Columns) <> 0 Then
                lColumn = .Columns.Find(What:="*", _
                              After:=.Range("A1"), _
                              LookAt:=Excel.XlLookAt.xlPart, _
                              LookIn:=Excel.XlFindLookIn.xlFormulas, _
                              SearchOrder:=Excel.XlSearchOrder.xlByColumns, _
                              SearchDirection:=Excel.XlSearchDirection.xlPrevious, _
                              MatchCase:=False).Column
            Else
                lColumn = 1
            End If
        End With

        MessageBox.Show(lColumn) 'Find Last Column


        xWorkbook.Close()
        xls.Quit()

반응형