繁体   English   中英

为什么在尝试从 Excel 工作表设置 word 文档时会出现运行时错误 424

[英]Why do I get a runtime error 424 when trying to set a word doc from an excel worksheet

到目前为止,下面的代码正在尝试检查文件夹中的单词 doc 是否在文档的前 5 个字母中包含某些文本。 当我尝试设置单词 doc 时,大多数情况下我都会遇到运行时错误。 知道我需要调查什么才能找到错误的来源吗?

Sub ConfereBudget()


Dim FSO As Object
Dim myFile As Object
Dim docConfer As Worksheet
Dim RngSCCA As Range
Dim RngSCCJTC As Range
Dim RngNABJC As Range
Dim RngOther As Range
Dim RngSCPPA As Range
Dim myFolder As Object
Dim docVic As Worksheet
Dim appWord As Object
Dim LastSave As Date
Dim introw As Integer
Dim i As Integer
Dim rng1088 As Range
Dim doc1088 As Object
Dim str1088 As String

Set FSO = CreateObject("Scripting.FileSystemObject")

'Set docVic = ThisWorkbook.Worksheets("Sheet1")
Set myFolder = FSO.getfolder(ThisWorkbook.Path)
'Set docConfer = ThisWorkbook.Worksheets("Sheet1")
Set docConfer = ThisWorkbook.Worksheets(1)
Set appWord = CreateObject("Word.Application.16")
Set RngSCCA = ThisWorkbook.Worksheets("SCCA-WTFC20").Range("A2:L2")
Set RngSCCJTC = ThisWorkbook.Worksheets("SCCJTC 55").Range("A2:L2")
Set RngNABJC = ThisWorkbook.Worksheets("NABCJ 30").Range("A2:L2")
Set RngOther = ThisWorkbook.Worksheets("Other Trainings").Range("A2:L2")
Set RngSCPPA = ThisWorkbook.Worksheets("SCPPA 40").Range("A2:L2")

appWord.Visible = False

For Each myFile In myFolder.Files
    LastSave = FileDateTime(myFile)
    If Right(myFile, 5) = ".docx" Then
        introw = docConfer.Cells(docConfer.Rows.Count, "B").End(xlUp).Row + 1
        i = 3
        'trying to determine if the word doc is a 1088 by looking at the first 5 characters of the document
        'unable to set the word doc
        str1088 = myFile
        Set doc1088 = appWord.documents.Open(str1088) ****Error here***

        Set rng1088 = doc1088.Range(Start:=0, End:=5)
        MsgBox (rng1088.Text)
    End If

Next



End Sub```


我的问题是我试图打开的文档已经打开。 我测试后没有关闭它。 现在我很尴尬。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM