tags:

views:

270

answers:

1

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

+2  A: 
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
Oorang