美文网首页
VBA 添加路径到Excel中

VBA 添加路径到Excel中

作者: 芝麻的绿豆 | 来源:发表于2018-07-30 22:24 被阅读0次

将一个或多个Excel文件路径添加到选中的单元格中,

Sub SelectFile01()

定义变量

    Dim l As Long

    Dim x, y As Long

    Dim path As String

获得当前选中单元格的行列号

    ' Get the location of the selected cell

    x = Selection.Row()

    y = Selection.Column()

    'MsgBox ("conlums is " & x & "row is :" & y)

选择文件,并添加到单元格中

    With Application.FileDialog(msoFileDialogFilePicker)

        .AllowMultiSelect = True  'select one

        .Filters.Clear    'clear

        .Filters.Add "Excel Files", "*.xlsx;*.xls"

        .Filters.Add "All Files", "*.*"

        .Show

        ' put all attachments into a cell and split by ";"

        For l = 1 To .SelectedItems.Count

            path = path + .SelectedItems(l) + ";"

        Next

        Cells(x, y) = path

    End With

End Sub

相关文章

网友评论

      本文标题:VBA 添加路径到Excel中

      本文链接:https://www.haomeiwen.com/subject/ifmqvftx.html