您的位置:程序门 -> vb -> 基础类



通过浏览打开文件在执行操作


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


通过浏览打开文件在执行操作[已结贴,结贴人:kurosawa]
发表于:2007-05-20 16:38:09 楼主
原本我的程序是通过在程序中指定路径打开特定的文件直接操作的
现在想加添加一个open钮并在textbox中显示打开的文件名
再按执行键对所打开的文件进行操作

现在我把两个程序分别贴出来
请大大们帮我进行连接


执行单一路径指定文件

private   sub   command1_click()
        dim   xlapp   as   new   excel.application
        dim   xlbook   as   excel.workbook
        dim   xlsheet   as   excel.worksheet
        dim   lsfilename   as   string
        dim   llrow   as   long
        dim   llcol   as   long
        dim   lstemp   as   string
        dim   n()   as   string
        lsfilename   =   app.path   &   "\sjdm "
     
        llrow   =   0
        set   xlbook   =   xlapp.workbooks.add()
        set   xlsheet   =   xlbook.worksheets(1)
        open   lsfilename   &   ".dat "   for   input   as   #1                              
        do   while   not   eof(1)                        
                line   input   #1,   lstemp                        
                n   =   split(lstemp,   chr(9))
                debug.print   lstemp
                llrow   =   llrow   +   1
                for   llcol   =   0   to   ubound(n)
                        xlsheet.cells(llrow,   llcol   +   1)   =   n(llcol)
                next
        loop
        close   #1
        xlbook.saveas   lsfilename   &   ".xls "
        xlbook.close   (true)
        xlapp.quit
        set   xlapp   =   nothing
end   sub


文件浏览打开程序:
private   sub   cmdopen_click()
on   error   resume   next
cdltest.cancelerror   =   true
cdltest.dialogtitle   =   "打开文件 "
cdltest.filename   =   " "
cdltest.filter   =   "所有文件   (*.*) ¦*.* "
cdltest.flags   =   cdlofncreateprompt   +   cdlofnhidereadonly
cdltest.showopen
if   err   =   cdlcancel   then   exit   sub
textboxopen.text   =   cdltest.filename
end   sub


如果需要源文件我可以发给大大,请亲自指教
发表于:2007-05-20 17:17:151楼 得分:30
dim   xlapp   as   new   excel.application
        dim   xlbook   as   excel.workbook
        dim   xlsheet   as   excel.worksheet
        dim   lsfilename   as   string
        dim   llrow   as   long
        dim   llcol   as   long
        dim   lstemp   as   string
        dim   n()   as   string
        cdltest.cancelerror   =   true
cdltest.dialogtitle   =   "打开文件 "
cdltest.filename   =   " "
cdltest.filter   =   "所有文件   (*.*) ¦*.* "
cdltest.flags   =   cdlofncreateprompt   +   cdlofnhidereadonly
cdltest.showopen
if   err   =   cdlcancel   then   exit   sub
lsfilename   =   cdltest.filename

          llrow   =   0
        set   xlbook   =   xlapp.workbooks.add()
        set   xlsheet   =   xlbook.worksheets(1)
        open   lsfilename   &   ".dat "   for   input   as   #1                              
        do   while   not   eof(1)                        
                line   input   #1,   lstemp                        
                n   =   split(lstemp,   chr(9))
                debug.print   lstemp
                llrow   =   llrow   +   1
                for   llcol   =   0   to   ubound(n)
                        xlsheet.cells(llrow,   llcol   +   1)   =   n(llcol)
                next
        loop
        close   #1
        xlbook.saveas   lsfilename   &   ".xls "
        xlbook.close   (true)
        xlapp.quit
        set   xlapp   =   nothing
发表于:2007-05-20 18:05:552楼 得分:0
单一的打开文件跟多个打开有什么区别,
就是多个打开时,注意它的打开顺序和打开时间就好了。
发表于:2007-05-20 19:25:143楼 得分:0
我把上面大大修改后的两段分别粘贴进了两个command后
添加好excel和dialog控件后
只能执行第一个打开程序
后面一个command   bottom执行不了对打开文件的操作
现实错误   要求对象
请问哪里错了
发表于:2007-05-20 22:05:384楼 得分:0
又试了一下
感觉大大是把两段语言合并成一个了
但执行时错误为找不到文件

我是想通过两个command键实现浏览打开和执行

请问该如何改进


快速检索

最新资讯
热门点击