2009-08-31 33 views
4

使用VBA我想將當前word文檔的副本發送到Web服務?如何才能將當前文檔作爲字節數組獲取?VBA WS工具包,如何獲取當前文件作爲字節數組

我知道如何使用web服務只是不知道如何獲取當前文件作爲二進制對象發送?

p.s.自今天上午以來我只使用VBA =)如此簡單的答案讚賞

回答

10
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 
相關問題