0
0

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) バイナリファイルを読んで、テキスト(16進)で書き出す

Posted at

バイナリファイルを読んで、テキスト(16進)で書き出す

sample.vbs

'/-------------------------------------
'バイナリファイルを読んで、テキスト(16進)で書き出す
'/-------------------------------------
Private Sub sample_read_binary_file_out_text_file()

Dim filenum As Integer
filenum = FreeFile
Dim filename As String
filename = "sample.zip"
Open ThisWorkbook.Path & "\" & filename For Binary As #filenum

Dim filenum2 As Integer
filenum2 = FreeFile
Dim filename2 As String
filename2 = "filename.txt"
Open ThisWorkbook.Path & "\" & filename2 For Output As #filenum2

Dim value As Variant
    Dim i As Integer
    i = 1
    Do Until EOF(filenum)
        value = AscB(InputB(1, #filenum))
        'Line Input #filenum, value
        If value <> "" Then
        'Debug.Print Right("00" & Hex((value)), 2)
        Print #filenum2, CStr(Right("00" & hex((value)), 2)); vbTab;
        i = i + 1
        If i > 16 Then
            Print #filenum2, ""
            i = 1
        End If
        End If
    Loop

Close #filenum2
Close #filenum

End Sub

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?