注册 登录
编程论坛 VB6论坛

VB批量读取Excel内容

yuk_yu 发布于 2012-12-19 02:46, 724 次点击
我有三个文件名以DATA开头的excel文件和一个文件名不是以data开头的文件,
如何实现只将文件名以DATA开头文件类容读入到listview1中后并删除他们?
不是以data开头的文件则忽略?
只有本站会员才能查看附件,请 登录
6 回复
#2
yuk_yu2012-12-19 12:35
回复 楼主 yuk_yu
期待大家帮忙!!
#3
wp2319572012-12-19 12:38
你会不会读一个excel的呢

一个会 个个会
#4
Artless2012-12-19 12:40
dir查文件
if left(文件名,4)="data" then 内容读入
#5
yuk_yu2012-12-19 13:12
回复 4楼 Artless
可以帮忙写一下代码吗?
#6
yuk_yu2012-12-19 15:11
回复 4楼 Artless
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Private Sub Command1_Click()
    Dim I As Integer, j As Integer
    Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = False
    FileName = Dir(App.Path & "\*.xls")
    Do While FileName <> ""
        If InStr(1, CStr(FileName), "Data", vbTextCompare) > 0 Then
            Set xlBook = xlApp.Workbooks.Open(App.Path & "\" & FileName)
            Set xlsheet = xlBook.Worksheets(1)
            Dim litem
            For I = 2 To 7
                Set litem = ListView1.ListItems.Add()
                litem.Text = xlsheet.Cells(I, 1)
                litem.SubItems(1) = xlsheet.Cells(I, 2)
                litem.SubItems(2) = xlsheet.Cells(I, 3)
                litem.SubItems(3) = xlsheet.Cells(I, 4)
            Next
            xlBook.Close (True)
            xlApp.Quit
            Kill App.Path & "\" & FileName
        End If
        FileName = Dir
    Loop
    Set xlApp = Nothing
    MsgBox "Done"
End Sub

问题解决了!!谢谢大家!!

[ 本帖最后由 yuk_yu 于 2012-12-19 16:22 编辑 ]
#7
wanshixm2013-03-01 23:35
工程加密了???
1