如何使用 VBA 读取二进制文件? [英] how can I read a binary file using VBA?

查看:23
本文介绍了如何使用 VBA 读取二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 Compaq Visual Fortran 编写的程序生成的二进制文件.如何读取特定行并将其保存在 Excel 工作表中?

I have a binary file that resulted from a program written in Compaq Visual Fortran. How can I read specific lines and save them in an Excel sheet?

推荐答案

如果要将整个文件读入一个大数组,可以使用如下代码:

If you want to read the entire file into one big array, you can use the following code:

Dim byteArr() As Byte
Dim fileInt As Integer: fileInt = FreeFile
Open "C:path	omyfile.ext" For Binary Access Read As #fileInt
ReDim byteArr(0 To LOF(fileInt) - 1)
Get #fileInt, , byteArr
Close #fileInt

结果与 Todd Owen 的答案相同,但没有使用外部库.

The result is identical to the answer by Todd Owen, but achieved without the use of external libraries.

这篇关于如何使用 VBA 读取二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆