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



vba实现excel 的ctrl+f功能查询


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


vba实现excel 的ctrl+f功能查询
发表于:2007-12-05 13:11:01 楼主
一个很简单的东西,就是做一个查询按钮,实现ctrl+f的功能。
sub   查询_click()
        cells.find(what:=textbox1.value,   after:=activecell,   lookin:=xlformulas,   lookat:=   _
                xlpart,   searchorder:=xlbyrows,   searchdirection:=xlnext,   matchcase:=false   _
                ,   searchformat:=false).activate

end   sub
 
    目前问题是如果查询的内容不存在,提示错误:对象变量或with块变量未设置(原因估计是excel查询找不减,弹出一个找不到的对话框),如何解决,大牛指教?
发表于:2007-12-05 13:19:411楼 得分:0
你可以用on error goto试试。
发表于:2007-12-05 13:31:502楼 得分:0
好像还是不行
发表于:2007-12-20 22:25:123楼 得分:0
sub       查询_click()  
                cells.find(what:=textbox1.value,       after:=activecell,       lookin:=xlformulas,       lookat:=       _  
                                xlpart,       searchorder:=xlbyrows,       searchdirection:=xlnext,       matchcase:=false       _  
                                ,       searchformat:=false).activate           /*问题在这:如果找不到的话就不会返回对象,所以对空对象使用active就会报错,建议加if语句解决

end       sub  


快速检索

最新资讯
热门点击