帮我看看这段代码嘛?不太明白,谢谢
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
--------------------编程问答-------------------- 问题在何处?? --------------------编程问答-------------------- 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
根本看不懂啊 --------------------编程问答-------------------- 该回复被版主删除 --------------------编程问答-------------------- 大家帮我看看这句是不是有问题?
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) --------------------编程问答-------------------- dim of as long
of = Application.GetOpenFilename(FileFilter:="WORD files(*.doc),*.doc,All files(*.*),*.*")
补充:VB , VBA