Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert image to the header/footer in MS-Word - using CNiWordDocument

I program my application to link the report to MS Word.  I hope to be able to insert image to header and footer (letter head and logo).  Is there anyway to do so?  I know how to insert image to the document body using document.InsertImage but do not know how to insert picture to the header/footer/.  I am using VC++ .NET.  Thanks for your help. 
 
Yajai
0 Kudos
Message 1 of 3
(26,183 Views)

Hey Yajai,

I do not believe there is a direct method to insert an image into a Header/Footer in VC++ .NET using CNiWordDocument.  However, it is possible to use the Microsoft Automation Interface to do this.  This can be done by using the CNiWordDocument class to create a Word document, and then passing the reference to that existing document to the Word Automation Interface.  The Word Automation Interface has many methods that are not available in the CNiWordDocument class.  You will want to look at the help files for Microsoft Word for more information.  The easiest way to do this is open up Microsoft Word, go to the help menu, select Microsoft Office Word Help, then select the table of contents, and under there should be a book that says Microsoft Word Visual Basic Reference.  This should have the information you are looking for.  Another way to do this would be to use the Macro recorder in Word to see what it actually does to select the Header/Footer and insert an image.  I have included a link on Microsoft's site that has a little more information as well.  The following code snippet describes how to create a word document with the CNiWordDocument class and pass the reference to the Word Automation Interface.  If you have any further questions regarding the Word Automation Interface, it might be best to consult the forums at Microsoft.  If you have any more questions about the CNiWordDocument class feel free to post them here.

Link to Microsoft:

http://support.microsoft.com/default.aspx?kbid=222101

Code Example:

Add the following to your stdafx.h (this assumes Office XP; the paths will change if you have an different version of Office):

#include "oleacc.h"
#include "atlbase.h"

#pragma warning(push)
#pragma warning(disable: 4278)

#import "C:\\Program Files\\Common Files\\Microsoft Shared\\Office10\\mso.dll" \
rename_namespace("OfficeXP")
using namespace OfficeXP;

#import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.olb" \
rename_namespace("VBE6")
using namespace VBE6;

#import "C:\\Program Files\\Microsoft Office\\Office10\\MSWORD.olb" \
rename("ExitWindows", "WordExitWindows") \
named_guids, \
rename_namespace("MSWord")
using namespace MSWord;

#pragma warning(pop)


In your main code, create the document using the CNiWordDocument class and pass a reference of that document to the Microsoft Word Automation interfaces.

CNiWordApplication application;
CNiWordDocument document = application.CreateDocument();

CComQIPtr<_Document> spDocument(document.GetDispatch(false));

Thanks,

Message Edited by Patrick P. on 01-09-2006 06:25 PM

Pat P.
Software Engineer
National Instruments
0 Kudos
Message 2 of 3
(26,177 Views)
is there a way to do the same thing by using wordreport.fp? or is there a C function I can call?
0 Kudos
Message 3 of 3
(15,476 Views)