SC1832381 2016-03-21 13:23 采纳率: 0%
浏览 2370

VB6.0中当操作Word(以docx结尾的)时候会出现实时错误‘4198’

Private Sub Command2_Click()

Dim i As Integer
Dim j As Integer
j = 0
For i = 1 To File1.ListCount
j = j + 1
Dim myword_1 As New Word.Application
Dim doc1 As New Word.Document
Dim lujing As String
Set myword_1 = CreateObject("word.application")
myword_1.Visible = False
lujing = File1.Path + "\" + File1.List(j - 1)
Set doc1 = myword_1.Documents.Open(lujing) '注:如果其中有以docx结尾的就会出错。
Dim st_1 As String
Dim st_2 As String
Dim st_3 As String
Dim Sid As String
Dim Sname As String
Dim SnameWithDot As String
Dim length As Integer
Dim dot As Integer

Dim title As String
Dim txtSQL As String
Dim mrc As ADODB.Recordset
Dim MsgText As String

'提取实验报告中的第一个表格中的内容
st_1 = doc1.Tables(1).Cell(4, 1).Range.Text
st_2 = doc1.Tables(1).Cell(5, 1).Range.Text
st_3 = doc1.Tables(1).Cell(6, 1).Range.Text
'连接数据库
Sid = Mid(File1.List(j - 1), 1, 15)
title = Mid(File1.List(j - 1), 16, 3)
SnameWithDot = Mid(File1.List(j - 1), 19)
length = Len(SnameWithDot)
dot = InStr(SnameWithDot, ".")
Sname = Mid(SnameWithDot, 1, dot - 1)
txtSQL = ""
txtSQL = "select * from Labor where id='" & Trim(Sid) & "' "
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = True Then
mrc.AddNew
   mrc.Fields(0).Value = Sid
   mrc.Fields(1).Value = title
   mrc.Fields(2).Value = Left(st_1, Len(st_1) - 1) ' Left(st_1, Len(st_1) - 1)联系上文的st_1 = doc1.Tables(1).Cell(4, 1).Range.Text就是提取的实验内容里的内容
   mrc.Fields(3).Value = Left(st_2, Len(st_2) - 1)
   mrc.Fields(4).Value = Left(st_3, Len(st_3) - 1)
   mrc.Fields(5).Value = Sname
   mrc.Update
   mrc.Close
   Text1.Text = Text1.Text + File1.List(j - 1) + "记录添加成功!" + vbCrLf
Else
   Text1.Text = Text1.Text + File1.List(j - 1) + "记录之前已添加!" + vbCrLf

End If
doc1.Close
myword_1.Quit

Next i
MsgBox "记录添加完成!"

End Sub

  • 写回答

1条回答

  • threenewbee 2016-03-21 22:48
    关注

    你的计算机上安装的word版本是否是2003或者更早的。

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog