0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VBAでバイナリファイルを読込むサンプル

Posted at

健忘録

'*****************************************************************************
'[概要] バイナリファイルを読込む
'[引数] ファイル名、読込むセルの位置、1行当たり何バイト表示するか
'*****************************************************************************
Public Sub LoadBinaryFile(ByVal strFilename As String, ByRef objCell As Range, Optional ColSize As Long = 16)
On Error GoTo ErrHandle
    Dim RowSize As Long
    RowSize = Int((FileLen(strFilename) + ColSize - 1) / ColSize)
    ReDim Data(1 To ColSize, 1 To RowSize) As Byte
        
    Dim File As Integer
    File = FreeFile()
    Open strFilename For Binary Access Read As #File
    Get #File, , Data
    Close #File

    Dim x As Long
    Dim y As Long
    For y = 1 To RowSize
        For x = 1 To ColSize
            objCell.Cells(y, x) = Data(x, y)
        Next
    Next
ErrHandle:
End Sub
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?