Storing binary data with a VSD file

  • Thread starter Marek Wasilewski
  • Start date
M

Marek Wasilewski

Hi
What I need to do is to be able to store a file inside a vsd file. This
file can be either text or binary, but most likely the latter.

I've seen previous postings by Bill Ken(?) with example code like
ActiveDocument.DocumentSheet.Data1 = "My text or binary data"

but I wasn't sure how you would do this for a binary data file.

Any help would be most appreciated.

Best regards,

Marek
 
M

Mai-lan [MS]

Hi, Marek: You have two options to do this.

Option 1: The easiest way in VBA would be to convert the binary to text
using the Hex() function. This method below works, but the string
concatenation is extremely slow.
Private Const file1 As String = "C:\abc.bmp"
Sub loadFile()
Dim nSize As Long
Dim data() As Byte
Dim str As String
Dim l As Long

nSize = FileLen(file1)
Open file1 For Binary Access Read As #1
' convert each byte in the file into a 2-char hex string
For l = 1 To nSize
data = Input(1, #1)
str = str & Right("0" & Hex(data(0)), 2)
Next
Close #1
ActiveDocument.DocumentSheet.Data1 = str End Sub

You would also need a hex to binary conversion method when restoring the
file.

Option 2: An alternate method would be to use SolutionXML and use the XML
DOM to serialize the binary. This is much easier to do in .NET programming
(here's a link for more on serialization in .NET:
http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconbinaryserialization.asp)
but you'll have to research how to do this using VBA.

Thanks,
Mai-lan
Microsoft Corp.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top