VBA WS Toolkit, how to get current File as Byte Array

后端 未结 1 1131
一个人的身影
一个人的身影 2020-12-18 07:49

Using VBA I want to send a copy of the current word document to a web service? How can is get the current document as a Byte Array?

I know how to use the web ser

相关标签:
1条回答
  • 2020-12-18 08:35
    Public Sub Example()
        Dim bytFile() As Byte
        bytFile = GetFileBytes("c:\test\dirdump.doc")
        ''// Do something with bytFile here.
    End Sub
    
    Public Function GetFileBytes(ByVal path As String) As Byte()
        Dim lngFileNum As Long
        Dim bytRtnVal() As Byte
        lngFileNum = FreeFile
        If LenB(Dir(path)) Then ''// Does file exist?
            Open path For Binary Access Read As lngFileNum
            ReDim bytRtnVal(LOF(lngFileNum) - 1&) As Byte
            Get lngFileNum, , bytRtnVal
            Close lngFileNum
        Else
            Err.Raise 53
        End If
        GetFileBytes = bytRtnVal
        Erase bytRtnVal
    End Function
    
    0 讨论(0)
提交回复
热议问题