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或者更早的。

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型