A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Reducing column width in a word table



 
 
Thread Tools Display Modes
  #1  
Old December 13th 05, 08:21 AM posted to microsoft.public.word.tables
external usenet poster
 
Posts: n/a
Default Reducing column width in a word table

Hi,

I need to allow the user to specify the table column width in the range
of 0.5cm to 0.1cm. When the value goes below 0.4, an exception "Value
out of range" is thrown.

I have appended the code snippet that I use. The exception is thrown
whenever the SetWidth method is called.

TIA
Karthik.

================================================== =====
#region Move to start of document.
Object start = 0;
Object end = 0;
Word.Range rng = wDoc.Range(ref start, ref end);
#endregion

#region Add the table.
rng.InsertParagraphAfter();
rng.InsertParagraphAfter();
rng.SetRange(rng.End, rng.End);
rng.Tables.Add(wDoc.Paragraphs[2].Range, 1, 8,
ref missingObj, ref missingObj);
// Set variable to point to new table.
Word.Table tbl = wDoc.Tables[1];
#endregion

#region Corrective Action
tbl.Cell(1,1).Range.Text = "Sample Text 1";
tbl.Cell(1,2).Range.Text = "Sample Text 2";
tbl.Cell(1,3).Range.Text = "Sample Text 3";
tbl.Cell(1,4).Range.Text = "Sample Text 4";
tbl.Cell(1,5).Range.Text = "Sample Text 5";
tbl.Cell(1,6).Range.Text = "Sample Text 6";
tbl.Cell(1,7).Range.Text = "Sample Text 7";
tbl.Cell(1,8).Range.Text = "Sample Text 8";

tbl.Range.Font.Size = 1;
tbl.LeftPadding = 0.0F;
tbl.BottomPadding = 0.0F;
tbl.TopPadding = 0.0F;
tbl.RightPadding = 0.0F;
#endregion

#region Set the column widths.
for(int columnCounter=1; columnCounter = tbl.Columns.Count;
columnCounter++)
{
if(columnCounter == 1)
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(marginTB.Text)),Word.WdRulerStyle.wdA djustNone);
}
else if((columnCounter != 1) && (columnCounter % 2 != 0))
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(spaceTB.Text)),Word.WdRulerStyle.wdAd justNone);
}
else
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(widthTB.Text)),Word.WdRulerStyle.wdAd justNone);
}
}
================================================== =====

Ads
  #2  
Old December 13th 05, 02:50 PM posted to microsoft.public.word.tables
external usenet poster
 
Posts: n/a
Default Reducing column width in a word table

If you don't get an answer here, try posting in one of the word.vba NGs.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"Karthik N" wrote in message
ups.com...
Hi,

I need to allow the user to specify the table column width in the range
of 0.5cm to 0.1cm. When the value goes below 0.4, an exception "Value
out of range" is thrown.

I have appended the code snippet that I use. The exception is thrown
whenever the SetWidth method is called.

TIA
Karthik.

================================================== =====
#region Move to start of document.
Object start = 0;
Object end = 0;
Word.Range rng = wDoc.Range(ref start, ref end);
#endregion

#region Add the table.
rng.InsertParagraphAfter();
rng.InsertParagraphAfter();
rng.SetRange(rng.End, rng.End);
rng.Tables.Add(wDoc.Paragraphs[2].Range, 1, 8,
ref missingObj, ref missingObj);
// Set variable to point to new table.
Word.Table tbl = wDoc.Tables[1];
#endregion

#region Corrective Action
tbl.Cell(1,1).Range.Text = "Sample Text 1";
tbl.Cell(1,2).Range.Text = "Sample Text 2";
tbl.Cell(1,3).Range.Text = "Sample Text 3";
tbl.Cell(1,4).Range.Text = "Sample Text 4";
tbl.Cell(1,5).Range.Text = "Sample Text 5";
tbl.Cell(1,6).Range.Text = "Sample Text 6";
tbl.Cell(1,7).Range.Text = "Sample Text 7";
tbl.Cell(1,8).Range.Text = "Sample Text 8";

tbl.Range.Font.Size = 1;
tbl.LeftPadding = 0.0F;
tbl.BottomPadding = 0.0F;
tbl.TopPadding = 0.0F;
tbl.RightPadding = 0.0F;
#endregion

#region Set the column widths.
for(int columnCounter=1; columnCounter = tbl.Columns.Count;
columnCounter++)
{
if(columnCounter == 1)
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(marginTB.Text)),Word.WdRulerStyle.wdA djustNone);
}
else if((columnCounter != 1) && (columnCounter % 2 != 0))
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(spaceTB.Text)),Word.WdRulerStyle.wdAd justNone);
}
else
{
tbl.Columns[columnCounter].SetWidth(wApp.CentimetersToPoints
(float.Parse(widthTB.Text)),Word.WdRulerStyle.wdAd justNone);
}
}
================================================== =====


  #3  
Old December 14th 05, 05:10 AM posted to microsoft.public.word.tables
external usenet poster
 
Posts: n/a
Default Reducing column width in a word table

Hi Suzanne,

Thanks for the suggestion. Will do it.

Regards
Karthik

  #4  
Old December 16th 05, 11:35 AM posted to microsoft.public.word.tables
external usenet poster
 
Posts: n/a
Default Reducing column width in a word table

Dear Suzanne,

Actually, prior to creating this new thread, I read the following post.


http://groups.google.com/group/micro...799f16a19b0ea5

It is about the same problem of reducing the column width. But the
discussion is about changing the width in the application and not using
VBA. I had followed your direction in that post to reduce the cell
margins and setting the font size to 1. I am able to do it through VBA
but when i try to set the width as 0.3cm or less than that, I end up
getting a "Value out of range" exception.

Can you please let me know if I am missing out something in my code.

Thanks,
Karthik N

  #5  
Old December 16th 05, 03:54 PM posted to microsoft.public.word.tables
external usenet poster
 
Posts: n/a
Default Reducing column width in a word table

I have no experience with VBA. Perhaps you should try posting in one of the
word.vba NGs.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"Karthik N" wrote in message
oups.com...
Dear Suzanne,

Actually, prior to creating this new thread, I read the following post.



http://groups.google.com/group/micro...799f16a19b0ea5

It is about the same problem of reducing the column width. But the
discussion is about changing the width in the application and not using
VBA. I had followed your direction in that post to reduce the cell
margins and setting the font size to 1. I am able to do it through VBA
but when i try to set the width as 0.3cm or less than that, I end up
getting a "Value out of range" exception.

Can you please let me know if I am missing out something in my code.

Thanks,
Karthik N


  #6  
Old December 19th 05, 06:45 AM posted to microsoft.public.word.tables
external usenet poster
 
Posts: n/a
Default Reducing column width in a word table

Oh... Ok. Thanks Anyways...

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
take yet another lesson from wordperfect "reveal codes" wordperfect is superior Microsoft Word Help 5 May 11th 09 07:58 PM
Table Format Style vs. Table Text Style WebColin Page Layout 11 December 1st 05 11:29 PM
How do I create a Word form like corel WP merge documents? dlee_at_mmsgov Microsoft Word Help 2 October 8th 05 06:29 AM
how do i set up template in vbeditor without proggramming language ARRRGH New Users 4 October 1st 05 03:19 AM
Table headers Sam Hobbs New Users 12 December 20th 04 07:18 PM


All times are GMT +1. The time now is 07:15 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 2004-2014 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.