从 Word 中提取嵌入文件时出错

发布于 2025-01-12 14:28:12 字数 1589 浏览 2 评论 0原文

我找到了一个关于提取word中嵌入文件的非常好的解决方案。但是当我提取文件时,此解决方案在 ExtractFile 函数中失败,并出现错误“下标超出范围”。 exe 或 .txt 请帮我。 如何从 Word 中提取嵌入文件

Sub ExtractFile(ByVal A0, ByVal A1, ByVal A2, ByVal A3, ByVal A4, ByVal OleFN, ByVal Z0, ByVal Z1, ByVal Z2, ByVal Z3, ByVal Z4, ByVal Z5, ByVal TextFN, ByVal offset, ByVal length)
    Dim i, j, nFile As Long
    Dim L() As Byte
    Dim B() As Byte
    
    If Not FileOpen(OleFN, B) Then Exit Sub
    For i = 0 To UBound(B) - 64
        If IIf(A0 < 0, B(i) < A0 * -1, B(i) = A0) And IIf(A1 = 256, B(i + 1) > 0, B(i + 1) = A1) And IIf(A2 = 256, B(i + 2) > 0, B(i + 2) = A2) And IIf(A3 = 256, B(i + 3) > 0, B(i + 3) = A3) And IIf(A4 = 256, B(i + 4) > 0, B(i + 4) = A4) Then Exit For
    Next
    If Z0 < 257 Then
        For j = UBound(B) - 16 To i - 64 Step -1
            If IIf(Z0 = 256, B(j) > 0, B(j) = Z0) And IIf(Z1 = 256, B(j + 1) > 0, B(j + 1) = Z1) And IIf(Z2 = 256, B(j + 2) > 0, B(j + 2) = Z2) And B(j + 3) = Z3 And IIf(Z4 = 256, B(j + 4) > 0, B(j + 4) = Z4) And IIf(Z5 = 256, B(j + 5) > 0, B(j + 5) = Z5) Then Exit For
        Next
    Else
        j = UBound(B)
    End If
    ReDim L(0 To j - i + length)
    For j = 0 To IIf(UBound(L) + i + offset > UBound(B), UBound(L) + i - length, UBound(L))
        L(j) = B(i + j + offset)
    Next
    nFile = FreeFile
    Open TextFN For Binary Access Write As nFile
    Put nFile, , L
    Close nFile
End Sub

ReDim 遇到错误并显示消息:“下标超出范围”

I found a very good solution about extracting embedded files in word. But this solution fails at ExtractFile function with error "subscript out of range" when I extract file. exe or .txt
Please help me.
How to extract embedded Files from Word

Sub ExtractFile(ByVal A0, ByVal A1, ByVal A2, ByVal A3, ByVal A4, ByVal OleFN, ByVal Z0, ByVal Z1, ByVal Z2, ByVal Z3, ByVal Z4, ByVal Z5, ByVal TextFN, ByVal offset, ByVal length)
    Dim i, j, nFile As Long
    Dim L() As Byte
    Dim B() As Byte
    
    If Not FileOpen(OleFN, B) Then Exit Sub
    For i = 0 To UBound(B) - 64
        If IIf(A0 < 0, B(i) < A0 * -1, B(i) = A0) And IIf(A1 = 256, B(i + 1) > 0, B(i + 1) = A1) And IIf(A2 = 256, B(i + 2) > 0, B(i + 2) = A2) And IIf(A3 = 256, B(i + 3) > 0, B(i + 3) = A3) And IIf(A4 = 256, B(i + 4) > 0, B(i + 4) = A4) Then Exit For
    Next
    If Z0 < 257 Then
        For j = UBound(B) - 16 To i - 64 Step -1
            If IIf(Z0 = 256, B(j) > 0, B(j) = Z0) And IIf(Z1 = 256, B(j + 1) > 0, B(j + 1) = Z1) And IIf(Z2 = 256, B(j + 2) > 0, B(j + 2) = Z2) And B(j + 3) = Z3 And IIf(Z4 = 256, B(j + 4) > 0, B(j + 4) = Z4) And IIf(Z5 = 256, B(j + 5) > 0, B(j + 5) = Z5) Then Exit For
        Next
    Else
        j = UBound(B)
    End If
    ReDim L(0 To j - i + length)
    For j = 0 To IIf(UBound(L) + i + offset > UBound(B), UBound(L) + i - length, UBound(L))
        L(j) = B(i + j + offset)
    Next
    nFile = FreeFile
    Open TextFN For Binary Access Write As nFile
    Put nFile, , L
    Close nFile
End Sub

ReDim encountered an error with message: "subscript out of range"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文