Excel VBA表中添加打开文件夹按钮

Private Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub CommandButton1_Click()
    Dim Dia1 As Object, Strr As String, PPath As String
    Set Dia1 = Application.FileDialog(msoFileDialogFilePicker)
    With Dia1
        .AllowMultiSelect = False '限制只能同时选择一个文件
        .Filters.Clear
        .Filters.Add "所有文件", "*.txt", 1 '限制显示的文件类型
        .Show
        For Each vrtSelectedItem In .SelectedItems
            PPath = vrtSelectedItem
        Next
    End With
    Open PPath For Input As #1
        Do While Not EOF(1)
            Line Input #1, Strr
            If Sheet1.Cells(1, 1) <> "" Then
                Sheet1.Cells(1, 1) = Sheet1.Cells(1, 1) & Chr(10) & Strr
            Else
                Sheet1.Cells(1, 1) = Sheet1.Cells(1, 1) & Strr
            End If
        Loop
    Close #1
End Sub

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

测量老覃

感谢您的支持!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值