从Excel VBA打开Microsoft Word文档时生成的运行时错误

时间:2017-09-29 15:49:48

标签: excel vba excel-vba ms-word

创建单词应用程序对象时收到运行时错误'13'异常。在异常之前,我也遇到了相对极端的延迟(大约20-30秒)。知道这可能是什么?我搜索了Stackoverflow,但我没有看到任何非常相似的内容。

我之前从未使用excel的word doc,所以这对我来说是新的。

以下代码:

Public Sub GetRawData()
    'Meant to translate data from a raw word file and format into excel
    Dim filePath As String
    Dim objWord As Application

    Set objWord = CreateObject("Word.Application")
    Dim objDoc As Word.Document

    'File management vars
    Dim oneLine As Paragraph
    Dim lineText As String
    filePath = "U:\Research_Dev Docs\DevFolder\Word Doc Translation In Excel For Phys\testWordDoc.docx"

    'Set word doc object using standard file directory and file name
    Set objDoc = objWord.Documents.Open(Filename:=filePath, Visible:=True)

    For Each oneLine In objDoc.Paragraphs
        'Pull in each line and eventually parse
        lineText = oneLine.Range.Text

        'DEBUG OUTPUT TO THE SCREEN FOR TESTING
        MsgBox (lineText)

    Next oneLine

End Sub

0 个答案:

没有答案