您的位置:程序门 -> vb -> vba



有关excel-vba的问题


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


有关excel-vba的问题[已结贴,结贴人:yxhltsx]
发表于:2007-12-24 16:26:03 楼主
我现在用vba写了一个小的程序,功能是:点击ok按钮可以打开一系列的excel文件(后缀名为.xls),并读出每一个文件的内容,写入另一个excel文件中.
现在这个功能基本实现了,只是在打开这一系列excel文件(后缀名为.xls)时是不是应该有一个属性可以控制它为隐形打开,即文件是打开了并能取出数据但是不要求操作者看到文件的真正打开.
我想问的就是有没有这样一个属性,如果有是哪一个?
我找了好久都没找到.
发表于:2007-12-24 16:36:221楼 得分:10
似乎是application.visible?
发表于:2007-12-24 16:38:552楼 得分:0
要不就是window.visible
发表于:2007-12-25 13:37:403楼 得分:0

首先谢谢这位的帮忙了,很感谢哦!
用application.visible道是能实现那个要求,可是它不仅仅是关闭了要打开的一系列excel文件,连我要写入信息的那个excel文件也关了,要查看结果还得要重新打开,这样很麻烦,而且不知道的还以为这样出错了,有没有更好的方法呢?
发表于:2007-12-25 14:09:324楼 得分:10
要创建另外一个excel对象,然后把这个对象的visible置成false,再用这个对象去打开一系列的excel,这样才可与被写的文件分开。
发表于:2007-12-25 14:38:595楼 得分:0
worksheet有visible属性的,所用按文件隐藏应该不是问题。
发表于:2007-12-25 17:42:546楼 得分:0
retrieving   a   value   from   a   closed   workbook
vba   does   not   include   a   method   to   retrieve   a   value   from   a   closed   workbook   file.   you   can,   however,   take   advantage   of   excel's   ability   to   work   with   linked   files.   this   section   contains   a   custom   vba   function   (getvalue,   which   follows)   that   retrieves   a   value   from   a   closed   workbook.   it   does   so   by   calling   an   xlm   macro,   which   is   an   old-style   macro   used   in   versions   prior   to   excel   5.   fortunately,   excel   still   supports   this   old   macro   system.

private   function   getvalue(path,   file,   sheet,   ref)
'       retrieves   a   value   from   a   closed   workbook
        dim   arg   as   string

'       make   sure   the   file   exists
        if   right(path,   1)   <>   "\"   then   path   =   path   &   "\"
        if   dir(path   &   file)   =   ""   then
                getvalue   =   "file   not   found"
                exit   function
end   if
'       create   the   argument
        arg   =   "'"   &   path   &   "["   &   file   &   "]"   &   sheet   &   "'!"   &   _
                range(ref).range("a1").address(,   ,   xlr1c1)

'       EXECute   an   xlm   macro
        getvalue   =   EXECuteexcel4macro(arg)
end   function


快速检索

最新资讯
热门点击