View Single Post
 
Old 04-09-2014, 04:38 AM
XmisterIS XmisterIS is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Sep 2013
Posts: 12
XmisterIS is on a distinguished road
Default How to read binary data from currently open file?

*** SOLVED ***

Here's the problem:

I have a web-based facility for uploading word documents. This facility parses the xml data of the document and extracts the data that is required.

I am now writing a macro that will allow the user to upload the document directly to the server via cURL at the click of a button on the Quick Access toolbar.

I have adapted the code from here (http://stackoverflow.com/questions/8...ry-file-to-var) to read in the document's binary data, as follows:

Code:
Public Sub Sandbox()
    filename = ActiveDocument.Path & "\" & ActiveDocument.name
    
    Dim f As Integer
    f = FreeFile()
    
    Open filename For Binary Access Read As #f
        bin2var = Space(FileLen(filename))
        Get #f, , bin2var
    Close #f
End Sub
The trouble is, of course, that I get a "permission denied" error because the file that I want to read is the currently open file!

It has been suggested that I write a macro which extracts the data required and then uploads it to the server, but from my point of view that is absurd - I already have a perfectly good PHP script to do the job, I don't want to re-invent the wheel.

How can I read the raw binary data of the currently open file?

*** SOLVED ***
No worries - sorted it myself.
Reply With Quote