红色字体的部分内容是录了VBA来修改的,但却word会出现有进程无法进行自动插入行及数据,请帮忙看看问题出在哪里;
If e.Form.Controls("DateTimePicker3").value Is Nothing Then
MessageBox.Show("完成日期:" & "不能为空,请检查")
Return
Else
Dim dr As Row = Tables("T_Report").Current
dr("报告状态") = True
dr("报告员") = User.name
dr.save()
Dim tm As String = ProjectPath & "Attachments\化妆品流通报告模板.doc" '指定模板文件
Dim fl As String = ProjectPath & "Reports\" & dr("报告编号") & " " & dr("样品名称") & ".Doc" '指定目标文件
Dim wrt As New WordReport(Tables("T_Report"),tm,fl) '定义一个WordReport
wrt.BuildOne(dr)
wrt.Quit
Dim app As New MSWord.Application
try
Dim fileName = ProjectPath & "Reports\" & Tables("T_Report").current("报告编号") & " " & Tables("T_Report").current("样品名称") & ".Doc" '指定目标文件
Dim doc As Object = app.Documents.Open(fileName)
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader
If app.Selection.Find.Execute("CTTREPORT") Then '查找到指定字符串
app.Selection.Text =" " & dr("报告编号") & "" '替换字符串
End If
app.Selection.GoTo(What:= app.wdGoToBookmark, Name:="数据结果表")
With app.ActiveDocument.Bookmarks
.DefaultSorting = app.wdSortByLocation
.ShowHidden = False
End With
MessageBox.show("1")
Dim rs As List (of DataRow) = DataTables("T_Item").Select("报告编号 = '" & dr("报告编号") & "'")
Dim cnt As Integer = "0"
For Each r As DataRow In rs
app.Selection.InsertRowsBelow(1)
MessageBox.show("2")
app.Selection.TypeText(Text:= cnt+1)
app.Selection.MoveRight(Unit:=app.wdCharacter, Count:=1)
app.Selection.TypeText(Text:=r("检测项目"))
app.Selection.MoveRight(Unit:=app.wdCharacter, Count:=1)
app.Selection.TypeText(Text:=r("检测方法"))
app.Selection.MoveRight(Unit:=app.wdCharacter, Count:=1)
app.Selection.TypeText(Text:=r("结果"))
app.Selection.MoveRight(Unit:=app.wdCharacter, Count:=1)
app.Selection.TypeText(Text:=r("标准要求"))
app.Selection.MoveRight(Unit:=app.wdCharacter, Count:=1)
app.Selection.TypeText(Text:=r("单位"))
app.Selection.MoveRight(Unit:=app.wdCharacter, Count:=1)
app.Selection.TypeText(Text:=r("判定"))
MessageBox.show("3")
Next
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument
app.Visible = True
catch ex As exception
app.Quit
finally
End try