Adding a watermark to a document

G

Garrold

Hi,

I have a problem trying to add a watermark to a word document. This is
the error I'm getting:

Error 6 The type 'Microsoft.Office.Core.MsoTriState' is defined in an
assembly that is not referenced. You must add a reference to assembly
'office, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c'.

I have the following using statements:

using Word = Microsoft.Office.Interop.Word;
using Microsoft.Office.Core;

And I've added the reference to the Microsoft Office 11.0 Object
library, which gives me the Microsoft.Office.Core, Word & VBIDE
references.

Here is a code snippet:

Word.Selection wSelection = WordApp.Application.Selection;
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Shape wShape;
WordDocument.Sections[1].Range.Select();
WordDocument.ActiveWindow.ActivePane.View.SeekView =
Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
wShape =
wSelection.HeaderFooter.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,
"TEST TEST TEST", "Arial", 1, MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, ref
oMissing);

Has anyone else encountered a problem trying to use the
Microsoft.Office.Core.MsoTriState enumerations?

Thanks
 
C

Cindy M.

Hi Garrold,

I take it you're automating Office (Word) 2003? This isn't an Addin? And you don't
have two references to an Office.dll (can happen when creating a Shared Add-in and
cause problems)? I don't have any problems with msoTristate. But I do notice that
you've not fully qualified the second of the three parameters of this type.

Please note that the approach you're taking is not optimal. You should be working
with the Header/Footer object directly. Trying to work with a Selection in the
Header/Footer view is error-prone when using automation. Example:

wd.HeaderFooter hf =
wdDoc.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderF
ooterPrimary];
wd.Shape shp =
hf.Shapes.AddTextEffect(office.MsoPresetTextEffect.msoTextEffect1,
"TEST TEST TEST", "Arial", 1, office.MsoTriState.msoFalse,
office.MsoTriState.msoFalse, 0, 0, ref missing);

I have a problem trying to add a watermark to a word document. This is
the error I'm getting:

Error 6 The type 'Microsoft.Office.Core.MsoTriState' is defined in an
assembly that is not referenced. You must add a reference to assembly
'office, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c'.

I have the following using statements:

using Word = Microsoft.Office.Interop.Word;
using Microsoft.Office.Core;

And I've added the reference to the Microsoft Office 11.0 Object
library, which gives me the Microsoft.Office.Core, Word & VBIDE
references.

Here is a code snippet:

Word.Selection wSelection = WordApp.Application.Selection;
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Shape wShape;
WordDocument.Sections[1].Range.Select();
WordDocument.ActiveWindow.ActivePane.View.SeekView =
Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
wShape =
wSelection.HeaderFooter.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffec
t.msoTextEffect1,
"TEST TEST TEST", "Arial", 1, MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, ref
oMissing);

Has anyone else encountered a problem trying to use the
Microsoft.Office.Core.MsoTriState enumerations?

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

Garrold

Hi Cindy,

Thanks for your post. I've changed my code as you suggested, to use
the Header/Footer object directly although I'm still having a problem
with the msoTriState.msoFalse property. I am automating Office Word
2003 com object to do a mail merge. I'm getting a couple of errors on
the tristate, here is a copy of my code and errors below:

object oMissing = System.Reflection.Missing.Value;
WordDocument.ActiveWindow.ActivePane.View.SeekView =
Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
Word.HeaderFooter wHeader =
WordDocument.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary];
Word.Shape wShape =
wHeader.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,

"TEST TEST TEST", "Arial", 1,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, ref
oMissing);

The type 'Microsoft.Office.Core.MsoPresetTextEffect' is defined in an
assembly that is not referenced. You must add a reference to assembly
'office, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c'.

The type 'Microsoft.Office.Core.MsoTriState' is defined in an assembly
that is not referenced. You must add a reference to assembly 'office,
Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.

Argument '1': cannot convert from
'Microsoft.Office.Core.MsoPresetTextEffect
[c:\WebFramework\Sites\Admin\CQ.Admin.Leads.PrivateCar.Business\obj\Debug\Interop.Microsoft.Office.Core.dll]'
to 'Microsoft.Office.Core.MsoPresetTextEffect []'

Argument '5': cannot convert from 'Microsoft.Office.Core.MsoTriState
[c:\WebFramework\Sites\Admin\CQ.Admin.Leads.PrivateCar.Business\obj\Debug\Interop.Microsoft.Office.Core.dll]'
to 'Microsoft.Office.Core.MsoTriState []'

Regards

Gaz

Hi Garrold,

I take it you're automating Office (Word) 2003? This isn't an Addin? And you don't
have two references to an Office.dll (can happen when creating a Shared Add-in and
cause problems)? I don't have any problems with msoTristate. But I do notice that
you've not fully qualified the second of the three parameters of this type.

Please note that the approach you're taking is not optimal. You should be working
with the Header/Footer object directly. Trying to work with a Selection in the
Header/Footer view is error-prone when using automation. Example:

wd.HeaderFooter hf =
wdDoc.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderF
ooterPrimary];
wd.Shape shp =
hf.Shapes.AddTextEffect(office.MsoPresetTextEffect.msoTextEffect1,
"TEST TEST TEST", "Arial", 1, office.MsoTriState.msoFalse,
office.MsoTriState.msoFalse, 0, 0, ref missing);

I have a problem trying to add a watermark to a word document. This is
the error I'm getting:

Error 6 The type 'Microsoft.Office.Core.MsoTriState' is defined in an
assembly that is not referenced. You must add a reference to assembly
'office, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c'.

I have the following using statements:

using Word = Microsoft.Office.Interop.Word;
using Microsoft.Office.Core;

And I've added the reference to the Microsoft Office 11.0 Object
library, which gives me the Microsoft.Office.Core, Word & VBIDE
references.

Here is a code snippet:

Word.Selection wSelection = WordApp.Application.Selection;
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Shape wShape;
WordDocument.Sections[1].Range.Select();
WordDocument.ActiveWindow.ActivePane.View.SeekView =
Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
wShape =
wSelection.HeaderFooter.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffec
t.msoTextEffect1,
"TEST TEST TEST", "Arial", 1, MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, ref
oMissing);

Has anyone else encountered a problem trying to use the
Microsoft.Office.Core.MsoTriState enumerations?

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


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

Cindy M.

Hi Garrold,
although I'm still having a problem
with the msoTriState.msoFalse property. I am automating Office Word
2003 com object to do a mail merge.
Please copy all the "using" statements at the top of the class into
your next reply.

Also, please check in your list of References: what "office" kinds of
references do you have? Particularly, I'm looking for anything that
may be duplicated or interfering.

Check each "office" type of reference and make sure the "Copy local"
property is set to FALSE. And check that each is referencing a version
11. Type library (making sure no conflicts with libraries from earlier
versions of Office).

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

Gaz

Hi Cindy,

Here are all the using statements of the class:
using System;
using System.Collections.Generic;
using System.Text;
using CQ.Admin.Leads.Utils;
using Word = Microsoft.Office.Interop.Word;
using office = Microsoft.Office.Core;
using CQ.Admin.Leads.Models;
using CQ.PrivateCar.DAL;
using CQ.PrivateCar.Models;
using CQ.Framework.Models;
using System.Collections;

There were 3 references added when I included the Microsoft Word 11.0
com object library:
Microsoft.Office.Core (Microsoft Office 11.0 Object Library)
VBIDE (Microsoft Visual Basic for Applications Extensibility 5.3)
Word (Microsoft Word 11.0 Object Library)

All the copy local settings are false.

Thanks

Gaz
 
C

Cindy M.

Hi Gaz,

Unfortunately, I don't see anything suspicious <sigh>

Two suggestions to try:
1. Instead of using Microsoft.Office.Core.MsoTriState, see what happens
if you type office (as in your using statment).MsoT And see what
Intellisense offers, always using TAB to accept a suggestion (assuming
you get any suggestions at all).

2. Create a new Windows Form project. Reference the Word COM library.
Pu a button on the form that starts Word, loads a document, then
creates the header/footer, using the same code and see if this gives
you the same problem (to determine whether its a system configuration
problem, or just an issue with the one project)
Here are all the using statements of the class:
using System;
using System.Collections.Generic;
using System.Text;
using CQ.Admin.Leads.Utils;
using Word = Microsoft.Office.Interop.Word;
using office = Microsoft.Office.Core;
using CQ.Admin.Leads.Models;
using CQ.PrivateCar.DAL;
using CQ.PrivateCar.Models;
using CQ.Framework.Models;
using System.Collections;

There were 3 references added when I included the Microsoft Word 11.0
com object library:
Microsoft.Office.Core (Microsoft Office 11.0 Object Library)
VBIDE (Microsoft Visual Basic for Applications Extensibility 5.3)
Word (Microsoft Word 11.0 Object Library)

All the copy local settings are false.

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

Gaz

Hi Cindy,

Thanks for your help, I will try your suggestions, if all else fails I
will the computer in to a box and go home!

I'll report back if I find a solution!

Thanks again!

Gaz
 
G

Gaz

I've tried this on a colleagues machine and it worked fine, I'm
thinking it is something to do with Visual Studio being installed
before MS Office, so I'm going to try a re-install of VS and see how I
get on!

Regards

Gaz
 
C

Cindy M.

<[email protected]>
<[email protected]>
Newsgroups: microsoft.public.office.developer.automation
NNTP-Posting-Host: 5-163.0-85.cust.bluewin.ch 85.0.163.5
Lines: 1
Path: number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!nntp.infostrada.it!feeder.news.tin.it!207.46.248.126.MISMATCH!TK2MSFTFEEDS01.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP03.phx.gbl
Xref: number1.nntp.dca.giganews.com microsoft.public.office.developer.automation:12047

Hi Gaz,
it was MS Office 2003 that needed the
re-install.
<Ugh>Thanks for coming back with that :) Another time, you
could try Help/Detect and Repair (perhaps save yourself the
re-install) from within any Office application.

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
:)
 

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