Sub Test()




Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = True

'파일 오픈 다이얼로그에 여러파일을 허가한다.

'그 외 다른 다이얼로그 존재

'MsoFileDialogType Enumeration 

'msoFileDialogFilePicker 3 File picker dialog box.

'msoFileDialogFolderPicker 4 Folder picker dialog box.

'msoFileDialogOpen 1 Open dialog box.

'msoFileDialogSaveAs 2 Save As dialog box.


fileChoi = Application.FileDialog(msoFileDialogOpen).Show

'리턴값이 0 일경우 다이얼로그 취소.

'            -1 정상적으로 다이얼로그 사용시.


Dim fileNum As Integer

Dim dataLine As String


Dim strArr() As String



If fileChoi <> 0 Then             '파일을 선택하였을때


    maxLine = 0

    findFlag = False

    

    For i = 1 To Application.FileDialog(msoFileDialogOpen).SelectedItems.Count  '선택된 파일개수

      strPath = Application.FileDialog(msoFileDialogOpen).SelectedItems(i)          '파일경로

    

      fileNum = FreeFile()

        Open strPath For Input As #fileNum          

       

 j = 1

        

        While Not EOF(fileNum)

                   

            Line Input #fileNum, dataLine

        

            strArr() = Split(dataLine, vbTab)

                    

            If UBound(strArr) = 0 Then

                

            Else     

                'Cells(i + 1, 1) = strArr(0)

                itemName = strArr(0)   '이름

                itemNo = strArr(3)

                

                For k = 1 To maxLine

                   

                    If Cells(k, 1) = itemName Then

                        

                        Cells(k, i + 1) = itemNo  '기존목록에있으면 개수만추가

                        

                        fineFlag = True

                        Exit For

                    

                    End If

                

                Next k

                

                If fineFlag = False Then

                    maxLine = maxLine + 1

                    Cells(maxLine, 1) = itemName '없으면  추가

                   Cells(maxLine, i + 1) = itemNo

                    

                End If

                

                

                'Cells(j, i) = strArr(0)

                

            End If

            

            

            fineFlag = False

            'MsgBox (LBound(strArr))

            'MsgBox (strArr(0))

            'MsgBox (dataLine)

            j = j + 1

       Wend                             '아이템 하나 탐색 종료

    

    Next i                             '파일 하나 탐색 종료

    

End If


'For i = 1 To filePath.Size


    'MsgBox (filePath(i - 1))

'Next i

    


End Sub










참고: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-filedialog-property-excel

       http://software-solutions-online.com/excel-vba-open-file-dialog/

       https://www.exceltrick.com/formulas_macros/vba-split-function/

+ Recent posts