Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ms-word

vba

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 service just not sure how to get the current file as a binary object to send?

p.s. I have only been using VBA since this morning =) So simple answers are appreciated

like image 864
Daveo Avatar asked Aug 31 '09 06:08

Daveo


1 Answers

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
like image 90
Oorang Avatar answered Sep 18 '22 05:09

Oorang