VBA WS工具包,如何获取当前文件为字节数组 [英] VBA WS Toolkit, how to get current File as Byte Array

查看:110
本文介绍了VBA WS工具包,如何获取当前文件为字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用VBA我想将当前Word文档的副本发送到Web服务?如何将当前文档获取为字节数组?

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?

我知道如何使用Web服务,只是不确定如何将当前文件作为二进制对象发送?

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.从今天早上开始,我才一直在使用VBA =)因此,简单的答案值得赞赏

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

推荐答案

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

这篇关于VBA WS工具包,如何获取当前文件为字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆