VBA 弹框选择文件路径

Sub chooseDocumentPath()
'Auther 云浮清秋
'弹框选择文件路径
'----------------------------------------------
    Dim dataExcel, Workbook, dataSheet, filePath
    Dim totalRow  As Integer
  
    Set dataExcel = CreateObject("Excel.Application")

    filePath = Application.GetOpenFilename(Title:="弹框显示的标题文本内容", MultiSelect:=False) '可以选择各种格式的文件

    '  filePath = Application.GetOpenFilename("Excel Files (*.xls*), *.Excel")     '必须选择excel格式的文件



    If   filePath <> False Then 
        Set Workbook = dataExcel.Workbooks.Open(filePath)

        Set dataSheet = Workbook.Worksheets(1)

On Error GoTo noData

        totalRow = dataSheet.UsedRange.Find(what:="*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
        For i = 2 To totalRow
              Sheets("sheet1").Cells(i, 1) = dataSheet.Cells(i, 1)
              Sheets("sheet1").Ce

你可能感兴趣的:(VB/VBA,vba,excel)