![]() |
|
#1
|
|||
|
|||
![]()
Hi,
Please I want format selected table in academic style by VBA code without applying manual styling for each table in my paper as following 314.png Also, using alternate rows coloring (in some papers) 315.png Thanks |
#2
|
||||
|
||||
![]()
From where are you getting the Academic Style?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Thanks for reply,
Take look at any research paper and you will find academic style for tables, as many journals require that, for example Just a moment... Just a moment... https://static.cambridge.org/binary/...ub-status=live https://static.cambridge.org/binary/...48216_tab5.gif Aripiprazole in the treatment of the psychosis prodrome | The British Journal of Psychiatry | Cambridge Core |
#4
|
||||
|
||||
![]()
Your links point to a variety of table layouts. It's impossible to know from that what you actually expect. It's also impossible to create a single table Style that accommodates all those formats.
The following macro creates an "Academic" table Style that might work in some scenarios. Code:
Sub AcademicTableStyle() With ActiveDocument .Styles.Add Name:="Academic", Type:=wdStyleTypeTable With .Styles("Academic") 'Set the table body alignment .ParagraphFormat.Alignment = wdAlignParagraphRight With .Table 'Set the alignments for the first column and row .Condition(wdFirstRow).ParagraphFormat.Alignment = wdAlignParagraphLeft .Condition(wdFirstColumn).ParagraphFormat.Alignment = wdAlignParagraphLeft 'Make the first row Bold .Condition(wdFirstRow).Font.Bold = True 'Set cell padding - to keep text away from edges .TopPadding = InchesToPoints(0) .BottomPadding = InchesToPoints(0) .LeftPadding = InchesToPoints(0.125) .RightPadding = InchesToPoints(0.125) 'Clear all borders & shading .Borders(wdBorderLeft).LineStyle = wdLineStyleNone .Borders(wdBorderRight).LineStyle = wdLineStyleNone .Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone .Borders(wdBorderVertical).LineStyle = wdLineStyleNone .Shading.Texture = wdTextureNone .Shading.ForegroundPatternColor = wdColorAutomatic .Shading.BackgroundPatternColor = wdColorAutomatic 'Set the bottom border for the table .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle .Borders(wdBorderBottom).LineWidth = wdLineWidth050pt .Borders(wdBorderBottom).Color = wdColorAutomatic 'Set the top & bottom border for the first row .Condition(wdFirstRow).Borders(wdBorderBottom).LineStyle = wdLineStyleSingle .Condition(wdFirstRow).Borders(wdBorderBottom).LineWidth = wdLineWidth050pt .Condition(wdFirstRow).Borders(wdBorderBottom).Color = wdColorAutomatic .Condition(wdFirstRow).Borders(wdBorderTop).LineStyle = wdLineStyleSingle .Condition(wdFirstRow).Borders(wdBorderTop).LineWidth = wdLineWidth050pt .Condition(wdFirstRow).Borders(wdBorderTop).Color = wdColorAutomatic 'Configure the row banding .Condition(wdOddRowBanding).Shading.Texture = wdTextureNone .Condition(wdOddRowBanding).Shading.ForegroundPatternColor = wdColorAutomatic .Condition(wdOddRowBanding).Shading.BackgroundPatternColor = wdColorGray125 .Condition(wdEvenRowBanding).Shading.Texture = wdTextureNone .Condition(wdEvenRowBanding).Shading.ForegroundPatternColor = wdColorAutomatic .Condition(wdEvenRowBanding).Shading.BackgroundPatternColor = wdColorAutomatic 'Set the table alignment .Alignment = wdAlignRowCenter 'Set how many rows & columns to group for banding .RowStripe = 1 .ColumnStripe = 0 End With End With End With End Sub Code:
Sub AddTable() Dim Tbl As Table 'Create a basic 4-row 3-column table that autofits the column width Set Tbl = ActiveDocument.Tables.Add(Range:=Selection.Characters.Last, NumRows:=4, NumColumns:=3, DefaultTableBehavior:=wdWord8TableBehavior) With Tbl 'Make the first row repeat is the table spans a page break .Rows.First.HeadingFormat = True 'Set the row height rules .Rows.HeightRule = wdRowHeightAtLeast .Rows.Height = InchesToPoints(0.25) 'Apply the Academic Style .Style = "Academic" 'Apply the row banding .ApplyStyleRowBands = True End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Thanks for your help
I just provide an examples for academic table style, which is in general has boarder for top and bottom and all other side none (the first image in my post). Your first code each time make a style with the name academic and does not make sense, your second macro works fine for adding a new table, which is not my need, as I want to apply style of second macro for selected table. Thanks |
#6
|
||||
|
||||
![]() Quote:
Quote:
You don't need to run the AddTable macro at all, if you don't want to. That's been provided just to hel[ ypu create new tables in the "Academic" Style. You should be able to select any existing table and apply the "Academic" Style to it, if that's all you want to do.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
List acronyms from selected tables after them with style | Winrow | Word VBA | 6 | 06-25-2022 03:27 AM |
![]() |
Last Chance | Word | 3 | 06-09-2021 12:52 PM |
academic standard pagination in margin | Tim-A | Word | 1 | 10-26-2016 05:18 AM |
![]() |
ubns | Word | 1 | 08-02-2012 04:09 AM |
![]() |
Frednd | Word | 1 | 02-25-2011 04:55 PM |