Programmatically insert a Works object in a word document

G

GDD

Hi,
I have got a problem to program a simple button that enables user to add a
Works file in his document.
In Word 2007, when I do "Insert>Object> Microsoft Works", I have a Works
document which is inserted.
However, when I try to do it programmatically in C# :
selection.InlineShapes.AddOLEObject(ref oClassType, ref pathToFile, ref
lienAvecFichier, ref oFalse, ref oIconFileName, ref oMissing, ref oIconLabel,
ref oMissing);
If the file exists, it works perfectly.
The trouble begin when I want to create a new object with these code lines :
Object oClassType = "Works.Worksheet.6";
selection.InlineShapes.AddOLEObject(ref oClassType, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing);
When I attempt to insert a new Works object, it tells me that Works is not
installed. I tried various version of Works.Worksheet.x x from 1 to 8 without
success.
A solution ?
Thank you in advance,
GDD
 
C

Cindy M.

Hi =?Utf-8?B?R0RE?=,

And is Works installed?

Even if it is... You say when you do this "by hand" you get a Works "document".
But in your code you want to create a "worksheet". Are you able to create a
worksheet "by hand"?

Last resort: distribute an empty Works file of the type you need with your
solution. Create a copy of that file, save it to disk, then insert it into the
document. The user won't know it's from a file you copied...
I have got a problem to program a simple button that enables user to add a
Works file in his document.
In Word 2007, when I do "Insert>Object> Microsoft Works", I have a Works
document which is inserted.
However, when I try to do it programmatically in C# :
selection.InlineShapes.AddOLEObject(ref oClassType, ref pathToFile, ref
lienAvecFichier, ref oFalse, ref oIconFileName, ref oMissing, ref oIconLabel,
ref oMissing);
If the file exists, it works perfectly.
The trouble begin when I want to create a new object with these code lines :
Object oClassType = "Works.Worksheet.6";
selection.InlineShapes.AddOLEObject(ref oClassType, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing);
When I attempt to insert a new Works object, it tells me that Works is not
installed. I tried various version of Works.Worksheet.x x from 1 to 8 without
success.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
G

GDD

Thank you for your answer.

"And is Works installed?"
Yes it is. (Microsoft Works version 6.0)

When I try to insert an object in C# from a file, this file is a *.xlr. What
I mean is that I insert a worksheet created with Works. Sorry for the
misunderstanting with "document".
I think that if Word succeeded in adding a new Works worksheet object "from
nothing", I could do the same in C#.
Moreover, I thought that a dll could be missing, but I succeeded in adding
an OLE object from a file. That is the reason why I do not think that a dll
is missing.
Finally, it is clear that one way to solve this problem is to create an
empty document and to copy it whenever the user needs to add a new Works
worksheet. But I have to deploy this solution on a large number of PCs that
is why I do not think that it is an interesting solution.
To my mind, the problem is coming from the line : "Works.Worksheet.6".
Maybe this line is wrong ? Is there a way to find the classtype of an
existing Works file in order to verify this line ?
Regards
 
C

Cindy M.

Hi =?Utf-8?B?R0RE?=,
To my mind, the problem is coming from the line : "Works.Worksheet.6".
Maybe this line is wrong ? Is there a way to find the classtype of an
existing Works file in order to verify this line ?
Try recording a VBA macro in Word while inserting the "object". The macro
should give you the class type.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
G

GDD

Perfect ! Actually, the classtype is : "MSWorks4Sheet".
Thank you very much for your assistance.
 

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