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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献