2009-08-31 3 views
4

VBA 사용 현재 단어 문서의 복사본을 웹 서비스로 보내시겠습니까? 현재 문서를 바이트 배열로 가져 오는 방법은 무엇입니까?VBA WS Toolkit, 현재 파일을 바이트 배열로 가져 오는 방법

웹 서비스를 사용하는 방법을 알고 현재 파일을 보내는 바이너리 개체로 가져 오는 방법을 모르십니까?

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 
관련 문제