Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

Word automation different when word is hidden

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Claus Nielsen - 02 Jan 2005 18:53 GMT
Hello all

I'm having a problem with automating word on the .NET platform with C#.

Using the command:
oDoc = oWordApplic.Documents.Open(ref fileName, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing,
ref missing, ref missing, ref isVisible,ref missing,ref missing,ref missing,
ref missing);

... you can set if you want to be visible using the object isVisible = true
or false.
But when Word is hidden, the width of the tables is not the same, as when
Word is visible.

Does anyone know anything that can help me, or get me in contact with
someone somewhere?

Hope someone can help! Pretty urgent..

Regards
Claus Nielsen

Signature

Remove the .invalid.com from email address to send me replies.

Jean-Guy Marcil - 03 Jan 2005 18:04 GMT
Claus Nielsen was telling us:
Claus Nielsen nous racontait que :

> Hello all
>
[quoted text clipped - 11 lines]
> But when Word is hidden, the width of the tables is not the same, as
> when Word is visible.

???
Without knowing what it is you are doing, it is difficult to comment on this
particular problem.

If you are using the Selection object, then it is perfectly normal that the
result is different if Word is visible or not.
Try using not the Range object.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Claus Nielsen - 03 Jan 2005 18:26 GMT
Hello Jean, thank you for posting!

I seem to have a problem doing what you suggested. I use the .Selection
property to select Tables.Add.
Tables.Add method is described in VS.NET like this:
Tables.Add(Word.Range Range, int NumRows, int NumColumns, ref object
DefaultTableBehavier, ref object AutoFitBehavier)

... so I don't see how I can avoid using a range property, when the
Tables.Add method take a Word.Range parameter as the first argument?

This is translated from VB makro:
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
       3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
       wdAutoFitFixed

Here is my C#:
object defaultTableBehavior =
Word.WdDefaultTableBehavior.wdWord9TableBehavior;
object autoFitBehavior = Word.WdAutoFitBehavior.wdAutoFitContent;
activeTable = oWordApplic.Selection.Tables.Add(rng, 1, 2, ref
defaultTableBehavior, ref autoFitBehavior);

Can you help?

I can send you my class which I've devoloped for easier progress...

Regards
Claus Nielsen

> Claus Nielsen was telling us:
> Claus Nielsen nous racontait que :
[quoted text clipped - 22 lines]
> the result is different if Word is visible or not.
> Try using not the Range object.
Jean-Guy Marcil - 04 Jan 2005 17:25 GMT
Claus Nielsen was telling us:
Claus Nielsen nous racontait que :

> Hello Jean, thank you for posting!
>
[quoted text clipped - 6 lines]
> ... so I don't see how I can avoid using a range property, when the
> Tables.Add method take a Word.Range parameter as the first argument?

Sorry, my last sentence should have read:
   Try using the Range object.
instead of
   Try using not the Range object.

> This is translated from VB makro:
> ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1,
>        NumColumns:= _ 3, DefaultTableBehavior:=wdWord9TableBehavior,
>        AutoFitBehavior:= _ wdAutoFitFixed

   Range:=Selection.Range,
can also be:
   Range:=ActiveDocument.Paragraphs(1).Range,
for example, or any other valid range.
Of course, you can set the range to be the current cursor location with
   Range:=Selection.Range
Or assign that range to a range variable at the begining of the code, and
use this range variable in the Table.Add argument list.

> Here is my C#:
> object defaultTableBehavior =
[quoted text clipped - 4 lines]
>
> Can you help?

I do not know enough about C# sharp to comment on that code...

Only a tentative suggestion:
Can
   activeTable = oWordApplic.Selection.Tables.Add(rng, 1, 2, ref
   defaultTableBehavior, ref autoFitBehavior);
be
   activeTable = oWordApplic.oDoc.Tables.Add(rng, 1, 2, ref
   defaultTableBehavior, ref autoFitBehavior);

Where oDoc would be Document variable previously assigned to the active
document?
Would that help?

Hopefully, now that you have posted the C# code, someone will be along
shortly to assist you directly with that code.
Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Claus Nielsen - 05 Jan 2005 14:29 GMT
Hello again Jean

Thanks very much for your reply, and now it makes just a little bit more
sense :)

... but unfortunatly it did not help. I already use the:
Word.Range rng = oWordApplic.Selection.Range;
... so that would be the same as you suggested, right?

I tried using the:
Word.Range rng = oDoc.Paragraphs(1).Range;
.. but that just f.cked up my document, and got some serius COM errors in my
eventlog...

I changed the oWordApplic.Selection.Tables.Add to oDoc.Tables.Add.

This is my full function which inputs a table:
public void insertQuestionListTable()
{
 Word.Range rng = oWordApplic.Selection.Range;
 // Add the table.
 object defaultTableBehavior =
Word.WdDefaultTableBehavior.wdWord9TableBehavior;
 object autoFitBehavior = Word.WdAutoFitBehavior.wdAutoFitWindow;
 activeTable = oDoc.Tables.Add(rng, 1, 3, ref defaultTableBehavior, ref
autoFitBehavior);
 object style = "QuestionList";
 activeTable.set_Style(ref style);
 activeTable.PreferredWidthType =
Word.WdPreferredWidthType.wdPreferredWidthPercent;
 activeTable.PreferredWidth = 100;
}

This creates a table as converted from VBA. But unfortunatly when I input
text and set columns width, It f.cks up my table:
http://www.daimi.au.dk/~cln/errorPicture.JPG

This is what it should look like:
http://www.daimi.au.dk/~cln/correctPicture.JPG

Do you have any other suggestions? I'm getting kind of desperate. I even
tried just created a macro, and then call it from my app, but that didn't
work either. :(

Can you help?

Thanks !

Regards

> Claus Nielsen was telling us:
> Claus Nielsen nous racontait que :
[quoted text clipped - 54 lines]
> Hopefully, now that you have posted the C# code, someone will be along
> shortly to assist you directly with that code.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.