2009-08-31 23 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 
相关问题