Hi,
I tried to reply on the last thread, but the sample code I sent was too
large. The message I tried to send is below. The code sample is too
big to post. I'll email it directly to you.
Hi Alan,
I have modified the example to add an image as well as text into
a text box. I have attached a zip of C# project. It expects to
use Word 2003. If you use another version you will need to
recompile and probably redo the reference to Word - see below.
My demo puts up a window
with three buttons. They only work if you click them in order. The
top one: Open Word - starts Word and creates a new blank document.
You will probably need to retrieve the window from behind Word to
click the second button.
The second: Add Stuff - puts in three lines of text, puts a text box in
the middle, and adds text and a picture to the text box; The third
button just closes Word (without saving - see comments in source
code to save, or just do it manually before closing).
The picture loaded is c:\test.jpg - so you have to put a small picture
at the top level of c drive for the program to work as written. If you
have a picture elsewhere change the source code to reference it.
It might have been easier to do all this in VB.Net - C# isn't so friendly
with its object references and the lack of optional parameters; or in VBA
of some form. In any case the example shows the way the Word object
model works for this problem.
If you need to make your own C# project reference Word, it is
done as follows
1. Create a new Visual C# Project of kind "Windows Application"
2. Project Menu / Add Reference ... Browse
Navigate to wherever Word is installed and find MSWORD.OLB (the object
library)
On my machine this was at: C:\Program Files\Microsoft Office\OFFICE11\
OK to close the add reference dialog