Log in

View Full Version : Running code on table insertion.



Kamikaze
07-30-2007, 03:30 AM
Hi all,

Does anyone know of anyway to run code on table insertion?

We have a default style sheet with the justification set to justifed, i need to force the table to be left justified on insertion and there does not appear to be any settings to that effect.

Any ideas guys?

Many thanks
Tim

fumei
07-30-2007, 04:46 AM
What do you mean precisely by "default style sheet "?

Are you talking about XML documents? Are you talking about Word styles?

If it is Word styles, then the table should take the justification of the style attached to the paragraph at the insertion point. That is, the table contents will.

If a paragraph style is centered, and you insert a table at that paragraph, the table contents will be centered.

However, if, say, a paragraph is set for tight margins (Left indent 3", right, 1.5"), an inserted table will still fill the document margins (not the paragraph margins, even if set by the Style) - unless otherwise instructed.

Could you please clarify exactly what you are asking?

Your "style sheet" is justified, but you want the table LEFT justified. So, you want to override your style sheet - whatever that means.

As for code, if you are inserting the table by code, you can pretty much do what you want with it.

Kamikaze
07-30-2007, 05:14 AM
Hi fumei,

Sorry, i should have clarified the style sheet more, we use it kind of like our normal.dot and all new letters are based on this file as opposed to the normal.dot.

Within the file there are just lots of styles we use and autotext entries, nothing much else.

My request may seem strange to you and trust me i completely agree, i realise that when a table is inserted that the justification is the same as the current selection, i would just like to get around this.

i.e if the cursur was on a justified section and i inserted a table, rather than it being justified i would like it to be left justified. Basically going against what word does by default.

I did want to try and avoid having to customise the way a table was inserted but rather catch the event that is raised when a table is inserted.

Have i done a better job on explaining myself this time or is there anything else you would like to know.

Kind regards
Tim

Kamikaze
07-30-2007, 06:18 AM
I think for the time being i am just going to propose that if this is such an issue we overide the default behavior of inserting a new table.

Not a great solution but its the best i can think of currently, anyone else got any other suggestions?

Option Explicit
Sub insertTableCustom()
Dim insertTable As dialog
Application.ScreenUpdating = False
Set insertTable = Word.Dialogs(wdDialogTableInsertTable)
insertTable.Show
Selection.Tables(1).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.Collapse
Application.ScreenUpdating = True
End Sub

Cheers
Tim

fumei
07-30-2007, 11:24 AM
I still need you to clarify what it is you want to do.
i.e if the cursur was on a justified section and i inserted a table, rather than it being justified i would like it to be left justified. Does this mean the contents (what is IN the table), or does it mean the table itself?

Your code:
Selection.Tables(1).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft (never mind the use of Selection....) actions the contents of the table, NOT the table itself.

Please confirm.