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.