How to add a custom hidden object into MS Word Document

A

Ahmad Jalil Qarshi

hi!

i am working in VC7. I want to add a custom object (Image+Data) into the MS
Word Document. The Data will be something related to the image i.e name of
the image, format details etc and will be linked to the image shown on the
word document. Further more the data will be hidden. i.e. not visible to the
viewer of the document.

i have added the image into the Word document using the following code.

VARIANT var1; VariantInit(&var1);

VARIANT var2; VariantInit(&var2);

var1.vt = VT_BOOL; var1.boolVal = true; //SaveWithDocument

var2.vt = VT_BOOL; var2.boolVal = false; //LinkToFile

spSelect->InlineShapes->AddPicture("C:\\Documents and
Settings\\ahmadjalil\\My Documents\\My Pictures\\Sample.jpg",&var2,&var1);

VariantClear(&var1); VariantClear(&var2);



where spSelect is smart pointer of type Selection Object.



if some one knows about that. Please help me.


Thanks in advance.

Ahmad Jalil Qarshi
 
B

Bill Coan

Hi Ahmad,

When posting to multiple newsgroups, it's a good idea to list all the
newsgroups in the header of a single message. That way, replies posted to
one newsgroup will automatically appear in all of the newsgroups.

Hi Ahmad,

I don't know of any way in Word to permanently link hidden data to a
particular inline shape.

Inline shapes have an AlternativeText property that could be used to store
some information about the inline shape. The user won't normally see the
alternative text, but a curious user could certainly find it, so this
approach won't help if you're concerned with security in some way.

The easiest way to assign a value to the AlternativeText property is to make
sure you assign the inline shape to an object variable when the inline shape
is added to the document. The following code shows how to do this in Word's
vba macro language. It shouldn't be too hard to convert this into the
equivalent VC7 code.

'create a variable to serve as a
'pointer to the new inline shape
Dim objInlineShape As InlineShape

'insert a new inline shape and
'assign it to the variable
Set objInlineShape = _
Selection.InlineShapes.AddPicture(FileName:= _
"C:\test.jpg", _
LinkToFile:=False, _
SaveWithDocument:=True)

'Set the inline shape's alternative text
objInlineShape.AlternativeText = "My Hidden Code"

For a higher level of security, you use the AlternativeText property to
store the name of a Document Variable or a Custom Document Property, and
then store your hidden data in that Document Variable of Custom Document
Property. Code for working with these items is readily available in the Word
vba newsgroup via a google search.

I hope this helps.

Bill Coan
(e-mail address removed)
Ahmad Jalil Qarshi said:
hi!

i am working in VC7. I want to add a custom object (Image+Data) into the
MS
Word Document. The Data will be something related to the image i.e name of
the image, format details etc and will be linked to the image shown on the
word document. Further more the data will be hidden. i.e. not visible to
the
viewer of the document.

i have added the image into the Word document using the following code.

VARIANT var1; VariantInit(&var1);

VARIANT var2; VariantInit(&var2);

var1.vt = VT_BOOL; var1.boolVal = true; //SaveWithDocument

var2.vt = VT_BOOL; var2.boolVal = false; //LinkToFile

spSelect->InlineShapes->AddPicture("C:\\Documents and
Settings\\ahmadjalil\\My Documents\\My Pictures\\Sample.jpg",&var2,&var1);

VariantClear(&var1); VariantClear(&var2);



where spSelect is smart pointer of type Selection Object.



if some one knows about that. Please help me.


Thanks in advance.

Ahmad Jalil Qarshi
 

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