0

I am currently creating a large script to automate a Microsoft word document to pull out tables and put them into a new document. But I need to know when I reach the end of the document so I can move on to the next document.

Set objWord         = CreateObject("Word.Application")
Set objNewDoc       = objWord.Documents.Add()
Set objNewSelection = objWord.Selection
Set objDoc = objWord.Documents.Open( C:/Users/blahdoc.doc )
Set objSelection = objWord.Selection

This isn't the script but its how I defined and opened the documents for reading. I will happily insert more details if and when there needed.

I did look around for similar questions but didn't find any that apply. If you do sorry ahead of time ;)

4

1 回答 1

1

您实际上不必担心“到达文档末尾”。值得庆幸的是,这些表存储在一个Tables集合中,该集合是 a 的属性Word.Document。您可以像这样遍历所有表:

For Each oTable In objNewDoc.Tables
    If Left(oTable.Cell(1, 1).Range.Text, Len(oTable.Cell(1, 1).Range.Text) - 2) = "Some string" Then
        MsgBox "Found one!"
    End If
Next

我在把它放在一起时遇到的一个问题是所有单元格的文本都有一个由两个字符组成的单元格结束标记:一个回车符(ascii 13),然后是一个 BELL(ascii 7)。我曾经Left把它们去掉,这样我就可以将文本与字符串值进行比较,这就是我理解你正在尝试做的事情。

于 2013-11-01T22:27:58.550 回答