VBA读取文件

Dim Foldar As String
Private Sub btn(ByVal Target As Range)
    If Target.Row = 1 And Target.Column = 1 Then
     Search
    End If
End Sub

 

Sub Search()
    With Application.FileDialog(msoFileDialogFolderPicker)
        If .Show = True Then
            Foldar = .SelectedItems(1)
            'Range("D3").Value = Foldar
            selectjs (Foldar)
        End If
    End With
End Sub

 

 

Public Function selectjs(ByVal lujing As String)

    Dim MyFile As String

    Dim s As String     

   Dim i As Integer    

MyFile = Dir(lujing & "\" & "*.js")    

count = count + 1    

s = MyFile   

  output (s)     Do While MyFile <> ""      

   MyFile = Dir                

If MyFile = "" Then        

count = 0             Exit Do

        End If      

           count = count + 1     

        s = MyFile      

   output (s)    

Loop    

Debug.Print s

End Function

 

 

 

Public Function output(sname)

Range("A" & count).Value = sname

End Function

posted on 2015-05-29 17:24  dzh1990  阅读(1174)  评论(0编辑  收藏  举报