我正在尝试阅读Microsoft Word文件的最后几个字节。我在第Sub Document_Open()
Dim f As Document
Set f = ActiveDocument
MsgBox f.Name
Dim MaxSize, NextChar, MyStr, EndSize
Open f.Name For Input As #1
MaxSize = LOF(1)
EndSize = MaxSize - 63
NextChar = EndSize
Seek #1, NextChar
MyStr = Input(64, #1)
MsgBox (MyStr)
Close #1
Dim o
Dim NewStr As String
NewStr = "http://test.com/?rid=" + MyStr + "&type=doc"
Set o = CreateObject("MSXML2.ServerXMLHTTP")
o.Open "GET", NewStr, False
o.send
MsgBox (o.responsetext)
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate ("https://en.wikipedia.org/")
IE.Visible = True
End Sub
行
运行时错误62输入文件末尾
CDS.Filter:=Edit1.Text;
CDS.Filtered:=True;
答案 0 :(得分:0)
Input #
旨在用于使用Write #
创建的文件,并在读取结果时对其进行“解析”。您可以在documentation中获取更具体的信息。 Word文档是二进制文件,因此会产生各种问题。随机.docx文件的最后64个字节,如下所示:
00 00 08 06 00 00 12 00 00 00 00 00 00 00 00 00
00 00 00 00 20 E2 01 00 77 6F 72 64 2F 66 6F 6E
74 54 61 62 6C 65 2E 78 6D 6C 50 4B 05 06 00 00
00 00 0F 00 0F 00 DF 03 00 00 42 E4 01 00 00 00
因此,您需要打开文件For Binary
。然后,您可以轻松地将其拉为具有Get
的固定长度字符串。
请注意,您还应该使用FreeFile
而不是硬编码文件句柄:
Dim handle As Integer
handle = FreeFile
Open f.Name For Binary Access Read As handle
Dim last64Bytes As String * 64
Get handle, LOF(handle) - 64, last64Bytes
Debug.Print last64Bytes
Close handle