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



帮我看看这段代码嘛?不太明白,谢谢


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


帮我看看这段代码嘛?不太明白,谢谢
发表于:2007-04-10 11:42:42 楼主
public   function   kstzbaob()  
dim   app   as   new   word.application    
dim   doc   as   word.document    
dim   tabl1   as   word.table      
dim   tabl2   as   word.table      
dim   rd   as   recordset
dim   sel   as   word.selection    
dim   i,   j   as   integer
adodc1.recordset.movefirst
tsform.show
app.documents.open   ( "d:\li\vb\焊工管理系统\焊工考试通知 ")   表示打开文档对象集的一个文档
set   sel   =   app.selection       表示sel为一个选中的文本
          sel.moveright   unit:=wdword,   count:=5
          sel.text   =   "hk "   &   adodc1.recordset.fields( "计划编号 ")
          sel.movedown   unit:=wdline,   count:=1
          sel.text   =   adodc1.recordset.fields( "单位 ")   &   ": "
          sel.movedown   unit:=wdparagraph,   count:=1
          sel.moveright   unit:=wdword,   count:=5
          sel.text   =   adodc1.recordset.fields( "考试日期 ")   -   1
          sel.moveright   unit:=wdword,   count:=17
          sel.text   =   adodc1.recordset.fields( "考试日期 ")
          sel.movedown   unit:=wdparagraph,   count:=2
          '按考试信息生成word表格并设置属性
          set   tabl1   =   sel.tables.add(sel.range,   adodc1.recordset.recordcount   +   1,   6)
          tabl1.autoformat   (36)
          tabl1.allowautofit   =   true
          tabl1.columns.autofit
          tabl1.borders.outsidelinestyle   =   wdlinestylesingle
          tabl1.borders.outsidelinewidth   =   wdlinewidth150pt
          tabl1.columns(1).width   =   40
          tabl1.columns(2).width   =   40
          tabl1.columns(3).width   =   120
          tabl1.columns(4).width   =   30
          tabl1.columns(5).width   =   50
          tabl1.columns(6).width   =   80
          tabl1.leftpadding   =   0
          tabl1.rightpadding   =   0
          tabl1.autofitbehavior   (wdautofitwindow)
          '将满足条件的记录写入word表格
          with   tabl1
                adodc1.recordset.movefirst
                for   j   =   1   to   tabl1.columns.count
                  .cell(1,   j).range.font.bold   =   true
                next   j
                .cell(1,   1).range.text   =   "考试号 "
                .cell(1,   2).range.text   =   "姓   名 "
                .cell(1,   3).range.text   =   "培   考   项   目 "
                .cell(1,   4).range.text   =   "性质 "
                .cell(1,   5).range.text   =   "工位号 "
                .cell(1,   6).range.text   =   "理论考试 "
                for   i   =   2   to   tabl1.rows.count
                              if   adodc1.recordset.fields( "考试号 ")   <>   " "   then
                                    .cell(i,   1).range.text   =   adodc1.recordset.fields( "考试号 ")
                              else:   .cell(i,   1).range.text   =   " "
                              end   if
                              if   adodc1.recordset.fields( "姓名 ")   <>   " "   then
                                    .cell(i,   2).range.text   =   adodc1.recordset.fields( "姓名 ")
                              else:   .cell(i,   2).range.text   =   " "
                              end   if
                              if   adodc1.recordset.fields( "考试项目 ")   <>   " "   then
                                    .cell(i,   3).range.text   =   adodc1.recordset.fields( "考试项目 ")
                              else:   .cell(i,   3).range.text   =   " "
                              end   if
                              if   adodc1.recordset.fields( "考试性质 ")   <>   " "   then
                                    .cell(i,   4).range.text   =   adodc1.recordset.fields( "考试性质 ")
                              else:   .cell(i,   4).range.text   =   " "
                              end   if
                              if   adodc1.recordset.fields( "工位 ")   <>   " "   or   adodc1.recordset.fields( "技能场次 ")   <>   " "   then
                                    .cell(i,   5).range.text   =   adodc1.recordset.fields( "工位 ")   &   "- "   &   adodc1.recordset.fields( "技能场次 ")
                              else:   .cell(i,   5).range.text   =   " "
                              end   if
                              if   adodc1.recordset.fields( "理论日期 ")   <>   " "   or   adodc1.recordset.fields( "理论考试场次 ")   <>   " "   then
                                    if   adodc1.recordset.fields( "理论日期 ")   <>   "3000-1-1 "   then
                                            .cell(i,   6).range.text   =   adodc1.recordset.fields( "理论日期 ")   &   "上午 "   &   adodc1.recordset.fields( "理论考试场次 ")
                                    else:   .cell(i,   6).range.text   =   " "
                                    end   if
                              else:   .cell(i,   6).range.text   =   " "
                              end   if
                      adodc1.recordset.movenext
                      if   adodc1.recordset.eof   then
                            adodc1.recordset.movelast
                      end   if
                next   i
          end   with
'   sel.movedown   unit:=wdline,   count:=adodc1.recordset.recordcount   +   2
sel.movedown   unit:=wdline,   count:=1
  sel.movedown   unit:=wdparagraph,   count:=1
'sel.movedown   unit:=wdline,   count:=1
  '按考试项目生成表格并将数据写入表格
          set   tabl2   =   sel.tables.add(sel.range,   adodc2.recordset.recordcount   +   1,   4)
          tabl2.autoformat   (36)
          tabl2.allowautofit   =   true
          tabl2.columns.autofit
          tabl2.borders.outsidelinestyle   =   wdlinestylesingle
          tabl2.borders.outsidelinewidth   =   wdlinewidth150pt
          tabl2.columns(1).width   =   120
          tabl2.columns(2).width   =   80
          tabl2.columns(3).width   =   120
          tabl2.columns(4).width   =   80
          tabl2.leftpadding   =   0
          tabl2.rightpadding   =   0
          tabl2.autofitbehavior   (wdautofitwindow)
          with   tabl2
                  .cell(1,   1).range.font.bold   =   true
                  .cell(1,   2).range.font.bold   =   true
                  .cell(1,   3).range.font.bold   =   true
                  .cell(1,   4).range.font.bold   =   true
                  .cell(1,   1).range.text   =   "考试项目 "
                  .cell(1,   2).range.text   =   "wi   号 "
                  .cell(1,   3).range.text   =   "母材及规格 "
                  .cell(1,   4).range.text   =   "焊材及规格 "
                adodc2.recordset.movefirst
                for   i   =   2   to   tabl2.rows.count
                              if   adodc2.recordset.fields( "考试项目 ")   <>   " "   then
                                    .cell(i,   1).range.text   =   adodc2.recordset.fields( "考试项目 ")
                              else:   .cell(i,   1).range.text   =   " "
                              end   if
                              if   adodc2.recordset.fields( "wi ")   <>   " "   then
                                    .cell(i,   2).range.text   =   adodc2.recordset.fields( "wi ")
                              else:   .cell(i,   2).range.text   =   " "
                              end   if
                              if   adodc2.recordset.fields( "母材 ")   <>   " "   or   adodc2.recordset.fields( "母材1规格 ")   <>   " "   or   adodc2.recordset.fields( "母材2规格 ")   <>   " "   then
                                    .cell(i,   3).range.text   =   adodc2.recordset.fields( "母材 ")   &   "   "   &   adodc2.recordset.fields( "母材1规格 ")   &   adodc2.recordset.fields( "母材2规格 ")
                              else:   .cell(i,   3).range.text   =   " "
                              end   if
                              if   adodc2.recordset.fields( "焊材及规格 ")   <>   " "   or   adodc2.recordset.fields( "焊剂 ")   <>   " "   then
                                    .cell(i,   4).range.text   =   adodc2.recordset.fields( "焊材及规格 ")   &   "   "   &   adodc2.recordset.fields( "焊剂 ")
                              else:   .cell(i,   4).range.text   =   " "
                              end   if
                      adodc2.recordset.movenext
                      if   adodc2.recordset.eof   then
                            adodc2.recordset.movelast
                      end   if
                next   i
          end   with
          sel.movedown   5,   adodc2.recordset.recordcount   +   1
          sel.movedown   unit:=wdparagraph,   count:=3
          sel.moveright   unit:=wdword,   count:=13
          sel.text   =   date
tsform.hide
app.visible   =   true
end   function

发表于:2007-04-10 11:49:361楼 得分:0
问题在何处??
发表于:2007-04-10 14:14:292楼 得分:0
set   sel   =   app.selection       表示sel为一个选中的文本
          sel.moveright   unit:=wdword,   count:=5
          sel.text   =   "hk "   &   adodc1.recordset.fields( "计划编号 ")
          sel.movedown   unit:=wdline,   count:=1
          sel.text   =   adodc1.recordset.fields( "单位 ")   &   ": "
          sel.movedown   unit:=wdparagraph,   count:=1
          sel.moveright   unit:=wdword,   count:=5
          sel.text   =   adodc1.recordset.fields( "考试日期 ")   -   1
          sel.moveright   unit:=wdword,   count:=17
          sel.text   =   adodc1.recordset.fields( "考试日期 ")
          sel.movedown   unit:=wdparagraph,   count:=2
根本看不懂啊
发表于:2007-04-10 15:18:103楼 得分:0
该回复于2007-12-28 17:58:10被管理员或版主删除
发表于:2007-04-10 16:54:194楼 得分:0
大家帮我看看这句是不是有问题?
  dim   app   as   new   word.application
  dim   sel   as   word.selection
  app.documents.open   "\1.doc "
   
  set   sel   =   app.selection
             
 
          set   tabl1   =   sel.tables.add(sel.sections,   adodc1.recordset.recordcount   +   1,   6)
发表于:2007-04-11 11:48:265楼 得分:0
dim   of   as   long
of   =   application.getopenfilename(filefilter:= "word   files(*.doc),*.doc,all   files(*.*),*.* ")


快速检索

最新资讯
热门点击